简体   繁体   中英

Git merge after hard reset

This is the sequence

  1. Merged changes from master to dev
  2. Worked on dev, committing some changes
  3. Checkout master, did a hard reset to HEAD~1
  4. Checked out dev, tried to merge master
  5. Nothing happens

How can I bring the changes from the reset master branch into dev?

An easy way to fix this is to find the commit on dev that you removed in master and to run git revert REF , where REF is the hash/branch/tag/etc. of the commit you removed ( git log should come in handy to find the commit you want). This will create a new commit on dev that will undo the changes made in the commit you wanted to remove. It is also possible to rebase (and maybe hard reset) around this commit in the dev branch, but that could cause additional issues with modifying existing commits. git prefers that you create new commits that change or undo old commits instead of destructively modifying or removing existing commits.

What's happening in what you tried is that when you merge master into dev in step 4, git simply looks for commits that are in master that aren't in dev. Because you did a hard reset of master, this change is not represented as a commit, so this change doesn't get merged into dev.

Note that hard resetting can often make branching more complicated if you plan on having that modification go to more than one branch (and don't force push either).

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