benthayer / benthayer/git-gud

Level: Rewriting History 4 - "Cherry-Picking"

Open
#258 0 comments 0 reactions 1 assignee Claimed by @benthayer View on GitHub
level - educational
Dominant language
Python
Stars
558
Forks
53
PR merge metrics
No merged PRs in 30d

Description

```
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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.