Reputation: 512
Let's say I have the branch "staging" and I had created some files on it and committed them. I merged the "staging" branch to master accidentally.
Because it was too soon to merge (I still had work to do on the "staging" branch), I tried to revert the merge commit (using git revert
; I don't know the exact command because I used PyCharm's Git UI). Now those changes are reverted on the "master" branch and everything's good.
After finishing my work on the "staging" branch, I tried to merge it to master using these commands:
git checkout master
git pull
git merge staging
And this is git's response:
Auto-merging app/static/css/style.bundle.rtl.css
CONFLICT (content): Merge conflict in app/static/css/style.bundle.rtl.css
Removing app/static/js/main.js
Removing app/static/css/util.css
..
(All of my new files were listed here as removed)
..
Removing app/static/css/main.css
Automatic merge failed; fix conflicts and then commit the result.
Because of that old merge commit's reversion, git has detected all my changes on pre-existing files as conflicts and deleted all new files.
I aborted this operation by git merge --abort
, and now my files are all back. But I'm stuck and cannot merge this branch into master. What should I do?
I tried:
git merge staging -X theirs
, but this ignored all changes that have been made on master by other developersgit checkout staging && git merge master -s ours
, same problem as aboveUpvotes: 1
Views: 592
Reputation: 265211
When you revert, you tell Git that you don't want these changes (ever (again)). This also means that merging a branch with a revert will remove those changes or not merge them again.
In other words: when merging, only "new" changes are merged, not old ones (i.e. changes before a branch started).
If you decide that you actually need the reverted changes, you have to revert the revert, e.g.
git checkout branch
git revert hash-of-revert-commit
git checkout master
git merge branch
Upvotes: 3