简体   繁体   中英

Git merge previous commit from the same branch

Currently my brach is in state

A-B-C

what I want is

A-B-C-D

where D = A + C (take both changes)

I tried cherry picking A but it states nothing to commit, working tree clean.

Even for the same branch, you can use git cherry-pick to apply a previous version to the HEAD version.

And for the reason why git shows "nothing to commit, working tree clean" when you cherry-pick commit A, that's because changes on commit A is same as commit C . And you can double check by the command:

git diff <commitA> <commitC>

There will show no differences between the two commits.

And you do not need to add a new commit D since commit C already meet what you want.


Or if you want to reset to commit A or to the new version based on commit A , then you can use git reset command instead:

  • Use git reset --hard A to reet to the version for commit A directly;
  • Use git reset --soft A (or git reset A use --mixed option by default), git stash and git pop to resolve coflict manually and keep the version you need based on commit A .

You already have both A and C changes right? So if your current state is ABC and you want it to be ABCD where D = A + C , it does not makes any sense coz you already have A and C in your state.

Thus, when you are even cherry-picking, there is no "change".

I hope that answers your question :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM