Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
master
topic
$ git clone https://github.com/Joe-noh/motto_git
$ git checkout -b xxx-topic
$ vim test.rb
$ git commit -am 'modified'
$ g...
master
master
topic topic2
master
topic topic2
topic topic2
master
topic topic2
master
topic
master
topic
$ git checkout master
$ git pull origin master # master
$ git checkout xxx-topic
$ git rebase master
First, rewinding head...
1 class Hoge
2 <<<<<<< HEAD
3 def bar
4 =======
5 def baz
6 >>>>>>> master
7 end
8 end
NORMAL xxx-topic | test.rb
1 class Hoge
2 def bar
3 end
4 end
~
~
~
~
NORMAL xxx-topic | test.rb
$ vim test.rb
$ git add test.rb #
$ git rebase --continue
Applying: modify test.rb
topic
remote
local
topic
topic
topic
remote
local
--force-with-lease
topic(new)
master
topic
base master
topic topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
end
topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
end
topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
end
topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
end
topic(new)
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
@v = 1
end
top...
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
@v = 1
end
top...
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
@v = 1
?
end
t...
class Hoge
@v = 1
puts "C"
end
class Hoge
puts "A"
end
class Fuga
puts "B"
end
master base topic
class Fuga
@v = 1
?
end
t...
topic(new)
master
topic
$ git checkout master
$ git pull origin master # master
$ git checkout xxx-topic
$ git merge master
Auto-merging test.rb
C...
1 Merge branch 'master' into xxx-topic
2
3 # Conflicts:
4 # test.rb
5 #
6 # ...
7 # ...
8 # ...
NORMAL xxx-topic | test.rb
$ git push origin xxx-topic
commit 25ce283d9d3c4da27c0226e19654b91c1baf06e3
Author: Joe-noh <honzawa.j@pepabo.com>
Date: Tue Jun 21 12:17:38 2016 +090...
$ git revert 25ce283d #
[topic 1564168] Revert " "
1 file changed, 4 deletions(-)
commit 1564168380ec04480275ecd2b2ed9612001889fb
Author: Joe-noh <honzawa.j@pepabo.com>
Date: Tue Jun 21 12:58:14 2016 +090...
$ git checkout master
$ git pull origin master # master
$ git checkout -b revert-topic #
$ git revert ?????? # revert
$ gi...
commit 06a1792f1fb01b834d86514d15783eca4352606c
Merge: 97bf260 a392dd9
Author: Joe Honzawa <honzawa.j@pepabo.com>
Date: Mo...
$ git revert 06a1792
$ git revert 06a1792
error: Commit 06a1792… is a merge but no -m option was given.
fatal: revert failed
$ git revert 06a1792
error: Commit 06a1792… is a merge but no -m option was given.
fatal: revert failed
-m
master
topic
$ git revert 06a1792 -m 1
[topic 3d621f4] Revert "Merge pull request #2 from Joe-noh/topic"
1 file changed, 4 deletions(-)
$ git revert 06a1792 -m 1
[topic 3d621f4] Revert "Merge pull request #2 from Joe-noh/topic"
1 file changed, 4 deletions(-)...
git rebase -i <commit hash>
git cherry-pick <commit hash>
master rebase
master merge
git revert <commit>
git revert <merge-commit> -m 1
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
もっとgit
Upcoming SlideShare
Loading in …5
×

もっとgit

70,897 views

Published on

GMOペパボ新卒エンジニア研修の座学で使用した資料です。

コンフリクトへの対処方法、revertの方法を説明しました。

Published in: Technology
  • Be the first to comment

もっとgit

  1. 1. master topic
  2. 2. $ git clone https://github.com/Joe-noh/motto_git $ git checkout -b xxx-topic $ vim test.rb $ git commit -am 'modified' $ git push origin xxx-topic
  3. 3. master
  4. 4. master topic topic2
  5. 5. master topic topic2
  6. 6. topic topic2 master
  7. 7. topic topic2
  8. 8. master topic
  9. 9. master topic
  10. 10. $ git checkout master $ git pull origin master # master $ git checkout xxx-topic $ git rebase master First, rewinding head to replay your work on top of it... Applying: modify test.rb Using index info to reconstruct a base tree... M test.rb Falling back to patching base and 3-way merge...
  11. 11. 1 class Hoge 2 <<<<<<< HEAD 3 def bar 4 ======= 5 def baz 6 >>>>>>> master 7 end 8 end NORMAL xxx-topic | test.rb
  12. 12. 1 class Hoge 2 def bar 3 end 4 end ~ ~ ~ ~ NORMAL xxx-topic | test.rb
  13. 13. $ vim test.rb $ git add test.rb # $ git rebase --continue Applying: modify test.rb
  14. 14. topic remote local topic
  15. 15. topic topic remote local
  16. 16. --force-with-lease
  17. 17. topic(new) master topic
  18. 18. base master topic topic(new)
  19. 19. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic topic(new)
  20. 20. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic topic(new)
  21. 21. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic end topic(new)
  22. 22. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic end topic(new)
  23. 23. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga end topic(new)
  24. 24. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga end topic(new)
  25. 25. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga @v = 1 end topic(new)
  26. 26. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga @v = 1 end topic(new)
  27. 27. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga @v = 1 ? end topic(new)
  28. 28. class Hoge @v = 1 puts "C" end class Hoge puts "A" end class Fuga puts "B" end master base topic class Fuga @v = 1 ? end topic(new)
  29. 29. topic(new) master topic
  30. 30. $ git checkout master $ git pull origin master # master $ git checkout xxx-topic $ git merge master Auto-merging test.rb CONFLICT (content): Merge conflict in test.rb Automatic merge failed; fix conflicts and then commit the result. $ vim test.rb $ git commit -a
  31. 31. 1 Merge branch 'master' into xxx-topic 2 3 # Conflicts: 4 # test.rb 5 # 6 # ... 7 # ... 8 # ... NORMAL xxx-topic | test.rb
  32. 32. $ git push origin xxx-topic
  33. 33. commit 25ce283d9d3c4da27c0226e19654b91c1baf06e3 Author: Joe-noh <honzawa.j@pepabo.com> Date: Tue Jun 21 12:17:38 2016 +0900 commit f8263df7885c907e34b574524a7fc02702920d44 Author: Joe-noh <honzawa.j@pepabo.com> Date: Tue Jun 21 12:16:28 2016 +0900
  34. 34. $ git revert 25ce283d # [topic 1564168] Revert " " 1 file changed, 4 deletions(-)
  35. 35. commit 1564168380ec04480275ecd2b2ed9612001889fb Author: Joe-noh <honzawa.j@pepabo.com> Date: Tue Jun 21 12:58:14 2016 +0900 Revert " " This reverts commit 25ce283d9d3c4da27c0226e19654b91c1baf06e3. commit 25ce283d9d3c4da27c0226e19654b91c1baf06e3 Author: Joe-noh <honzawa.j@pepabo.com> Date: Tue Jun 21 12:17:38 2016 +0900
  36. 36. $ git checkout master $ git pull origin master # master $ git checkout -b revert-topic # $ git revert ?????? # revert $ git push origin revert-topic #
  37. 37. commit 06a1792f1fb01b834d86514d15783eca4352606c Merge: 97bf260 a392dd9 Author: Joe Honzawa <honzawa.j@pepabo.com> Date: Mon Jun 20 19:46:10 2016 +0900 Merge pull request #2 from Joe-noh/topic
  38. 38. $ git revert 06a1792
  39. 39. $ git revert 06a1792 error: Commit 06a1792… is a merge but no -m option was given. fatal: revert failed
  40. 40. $ git revert 06a1792 error: Commit 06a1792… is a merge but no -m option was given. fatal: revert failed -m
  41. 41. master topic
  42. 42. $ git revert 06a1792 -m 1 [topic 3d621f4] Revert "Merge pull request #2 from Joe-noh/topic" 1 file changed, 4 deletions(-)
  43. 43. $ git revert 06a1792 -m 1 [topic 3d621f4] Revert "Merge pull request #2 from Joe-noh/topic" 1 file changed, 4 deletions(-) $ git push origin revert-topic
  44. 44. git rebase -i <commit hash> git cherry-pick <commit hash>
  45. 45. master rebase master merge git revert <commit> git revert <merge-commit> -m 1

×