LoginSignup
0
0

More than 5 years have passed since last update.

悩んで学べるGitクイズ

Last updated at Posted at 2019-04-16

第1問:オフラインでのgit commit

あるファイルの修正を反映させるために、git commit しようとすると
突然ネットの接続が切れてしまった。git commitできる?できない?


//想定
$ mkdir testgit
$ cd testgit
$ git init
Initialized empty Git repository in /Users/john/testgit/.git/
$ echo "aaa" > test1.txt
$ git add .

(ここでオフラインになる)

$ git commit -m "first"

第2問:GitとGitHubでの設定項目

gitの初期設定で、下記のように名前とメールアドレスを設定した。ところがその後、GitHubの鍵の設定をしていると、「GitとGitHubで登録しているメールアドレスが異なる」ことに気づいた。果たしてこの状態でGitHubに、git pushできる?

・git上のメールアドレス設定:johndoe@gmail.com

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@gmail.com

・GitHub上のメールアドレス設定:johndoe@yahoo.co.jp
スクリーンショット 2019-04-16 20.21.30.png

第3問:Gitの原理

あるファイルをコミットした後に、修正を加えてまたコミットした。このときGitは「最初のファイルの内容とその差分を記録している」正しい?間違い?

・想定


$ mkdir testgit
$ cd testgit
$ git init
Initialized empty Git repository in /Users/john/testgit/.git/
$ echo "aaa" > test1.txt
$ git add .
$ git commit -m "first"
[master (root-commit) 9d84b43] first
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt
$ echo "ccc" >> test1.txt
$ cat test1.txt
aaa
ccc
$ git add .
$ git commit -m "second"
[master 9bc7d83] second
 1 file changed, 1 insertion(+)

第4問:画像のバージョン管理

ある画像ファイルをコミットした後に、修正を加えてもう一度コミットした。git checkoutで前のバージョンに戻った場合、修正前のファイルに戻っている?戻っていない?

$ mkdir image_test
$ cd image_test
$ git init
Initialized empty Git repository in /Users/john/image_test/.git/
$ curl -O http://cdn.keyakizaka46.com/images/14/a2c/e88af999620f2821c130062584f87/400_320_102400.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15898  100 15898    0     0   322k      0 --:--:-- --:--:-- --:--:--  323k
$ ls
400_320_102400.jpg
$ open 400_320_102400.jpg 
$ git add .
$ git commit -m "first"
[master (root-commit) 68188ea] first
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 400_320_102400.jpg
$ sips -f horizontal 400_320_102400.jpg 
/Users/user/image_test/400_320_102400.jpg
<CGColor 0x7ff0937040c0> [<CGColorSpace 0x7ff093503340> (kCGColorSpaceDeviceRGB)] ( 0 0 0 1 )
  /Users/john/image_test/400_320_102400.jpg
$ open 400_320_102400.jpg 
$ git add .
$ git commit -m "second"
[master 9d5ca29] second
 1 file changed, 0 insertions(+), 0 deletions(-)
 rewrite 400_320_102400.jpg (95%)
$ git log
commit 9d5ca29d65ac1dc549a8341ac8dfb5ff25d2fa9d (HEAD -> master)
Author: johndoe <johndoe@gmail.com>
Date:   Wed Apr 17 14:01:08 2019 +0900

    second

commit 68188ea3265e0b4a6cfb7f5e5d2954cc7b35291a
Author: johndoe <johndoe@gmail.com>
Date:   Wed Apr 17 14:00:03 2019 +0900

    first
$ git checkout 68188ea3265e0b4a6cfb7f5e5d2954cc7b35291a

(前のバージョンの画像に戻る?)

変更前
スクリーンショット 2019-04-17 14.12.16.png
変更後
スクリーンショット 2019-04-17 14.11.57.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0