Create a new warehouse, put only one text file in it, and make 6 commits respectively. At this time, git log --oneline should look like this
The content of the file is as follows
I want to discard the 442452d commit but keep the e09949e commit, here's how I do it
git reset --hard 260effc
Then git cherry-pick e09949e
A conflict broke out at this time, as shown below
What I don’t understand is why there is a conflict. It should be patched directly. It shouldn’t look like the picture above. e09949e’s submission should only contain ‘4’ and not ‘3’. If it is still needed If '3' is removed manually, what's the point of cherry-pick? I can just go into the file and delete it. Or is there something wrong with my usage? Ask God for guidance! ! !
Why not just git revert 442452d?
Commit records relative modifications and is related to the upper and lower lines of the modified content. If the previous line is lost, a conflict will be reported and needs to be resolved manually. If your two commits are no longer in related functions, you can revert directly.
In addition, using this method of reset --hard and then cherry-pick is not very good. Other collaborators may have added other commits in the middle, making subsequent conflict handling more difficult.
A better usage scenario for cherry-pick is when you want a separate feature from another branch on one branch.
Because of the difference in
e09949e
只包含4
,是针对前一个commit442452d
.But if you put
442452d
给去掉了,希望把e09949e
的父节点从442452d
指到260effc
now, there will indeed be conflicts.I’m not sure if my explanation is clear without moving pictures. If you have any questions, I suggest you play this tutorial first.