読者です 読者をやめる 読者になる 読者になる

Git ドリル 入門編(演習)をやってみた。その2。

Git入門 - ドキュメントとか読んで続きをやる。

適当な所にブランチを生やす

$ git show
commit 9be2a211b565dee342a054ed1315fe5ab5df5962
Author: y_sumida
Date: Thu Mar 22 23:49:04 2012 +0900

commit E

diff --git a/drill.txt b/drill.txt
index 35d242b..72f43f8 100644
--- a/drill.txt
+++ b/drill.txt
@@ -1,2 +1,3 @@
A
B
+E

$ git checkout -b topicF HEAD^^
Switched to a new branch 'topicF'

$ echo "F" >> drill.txt

$ git add drill.txt
warning: LF will be replaced by CRLF in drill.txt.
The file will have its original line endings in your working directory.

$ git commit -m "commit F"
[topicF warning: LF will be replaced by CRLF in drill.txt.
The file will have its original line endings in your working directory.
ddf08d1] commit F
warning: LF will be replaced by CRLF in drill.txt.
The file will have its original line endings in your working directory.
1 files changed, 1 insertions(+), 0 deletions(-)

状態確認。たぶん問題なし。

マージする

$ git checkout master
Switched to branch 'master'

$ git merge topicC
Auto-merging drill.txt
CONFLICT (content): Merge conflict in drill.txt
Automatic merge failed; fix conflicts and then commit the result.

コンフリクト発生!マージできないって。
・・・そりゃそうだ。
一つのファイルでやってんだから。

気を取り直して、修正。

$ git diff
diff --cc drill.txt
index 72f43f8,8422d40..0000000

      • a/drill.txt
      1. b/drill.txt

@@@ -1,3 -1,4 +1,8 @@@
A
B

    1. <<<<<<< HEAD

+E

    1. =======
  1. C
  2. D
    1. >>>>>>> topicC

$ vi drill.txt

$ git add drill.txt

$ git commit -m "commit E'"
[master d82a88c] commit E'

状態確認。

コミットの基点を変える

$ git checkout topicF
Switched to branch 'topicF'

Administrator@YOUR-A6CED2CF26 /c/gitwork/git_drill (topicF)
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: commit F
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging drill.txt
CONFLICT (content): Merge conflict in drill.txt
Failed to merge in the changes.
Patch failed at 0001 commit F

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".

当然コンフリクト発生。

$ git diff drill.txt
diff --cc drill.txt
index 7c6c205,c1c05c4..0000000
--- a/drill.txt
+++ b/drill.txt
@@@ -1,5 -1,2 +1,9 @@@
A
++<<<<<<< HEAD
+B
+E
+C
+D
++=======
+ F
++>>>>>>> commit F

Administrator@YOUR-A6CED2CF26 /c/gitwork/git_drill ((d82a88c...)|REBASE)
$ vi drill.txt

$ git rebase --continue
drill.txt: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add

addしろって怒られた。

$ git add drill.txt

$ git rebase --continue
Applying: commit F

状態確認。

コミットを取り消す

$ git branch
master
topicC
* topicF

$ git checkout master
Switched to branch 'master'

$ git reset --hard HEAD^^
HEAD is now at 895d5cf commit B

状態確認。

歴史の一本化

・・・わからん。
最後のスライドに「どこが入門やねん」とあるので、今はわかんなくても大丈夫なはず(?)

とりあえず解答見ながら勉強しよ。