benthayer / git-gud

Wanna git gud? Then get git-gud, and git gud at git!
MIT License
401 stars 42 forks source link

Level: Rewriting History 4 - "Cherry-Picking" #258

Open benthayer opened 3 years ago

benthayer commented 3 years ago
4) Cherry-picking - Cherry-picking is another action that changes the hash

Cherry-picking writes a new commit (with a new hash), but instead of changing the content like amending, cherry-picking will change the commit's parent.

Cherry-picking is for when you want to apply the changes from only one commit.

git gud status

Initial Commit (master):
Hash:
Files: File1

Work1:
Hash:
Files: File1, BadFile

Work2 (branch):
Hash:
Files: File1, BadFile, File2

By the way, you can see the difference here:
======= Simulating: git diff branch~ branch
Work2 added a File2!
<<<<<<<

======= Simulating: git log --oneline --all --graph
Blah
<<<<<<<

git gud status (after cherry-picking)

Initial Commit (master):
Hash:
Files: File1

Work1:
Hash:
Files: File1, BadFile

Work2 (branch):
Hash:
Files: File1, BadFile, File2

Work2 (master):
Hash:
Files: File1, File2

By the way, you can see the difference here:
======= Simulating: git diff master~ master
Work2 added a File2!
<<<<<<<

By the way, you can see the difference here:
======= Simulating: git diff branch~ branch
Work2 added a File2!
<<<<<<<

======= Simulating: git log --oneline --all --graph
Blah
<<<<<<<

Tree:

A) Starting tree
Initial (master)
    \
   work1 --- work2 (branch)

B) After rebasing
Initial --- work2'
    \
   work1 --- work2 (branch)

C)
Initial --- work2' --- Merge (master)
    \                   /
   work1 --- work2 (branch)