Consider this situation. I have 5 commits A-B-C-D-E. I want to use rebase -i so that commit B will have all changes of commit D. How can I do that ?
Asked
Active
Viewed 24 times
-1
-
duplicate https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean – Michael Henderson Jan 17 '18 at 15:12
-
Possible duplicate of [What does cherry-picking a commit with git mean?](https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean) – Michael Henderson Jan 17 '18 at 15:12
-
Possible duplicate of [How can I combine commit using git rebase](https://stackoverflow.com/questions/16676517/how-can-i-combine-commit-using-git-rebase) – phd Jan 17 '18 at 17:10
2 Answers
0
git rebase -i A
The editor pops with the content:
pick B
pick C
pick D
pick E
Edit the content:
pick B
squash D
pick C
pick E
Save and exit.

ElpieKay
- 27,194
- 6
- 32
- 53
0
You can simply do git rebase -i HEAD~4
and then you will see
pick ae2c481 B
pick 2b1007f C
pick bcda8c5 D
pick 8591cea E
# Rebase 69f1cd1..8591cea onto 69f1cd1 (4 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
then do
pick ae2c481 B
squash bcda8c5 D
pick 2b1007f C
pick 8591cea E

Siva Praveen
- 2,213
- 17
- 20
-
Thanks btw I wanted to ask one more thing. Consider the same I have commits A-B-C-D-E. Commit D added to my code for example one class. But I want from commit B to contain that change and delete this change in commit D. How can I do that ? – Druudik Jan 17 '18 at 15:57
-