Advertisements

Rolling git merge back to normal

I been using git for a while and I messed up a few times, especially on what branch I’m on and merging branches. The other day, I had checked out a branch and did some changes to my code, when I was done I wanted to merge the changes to the master.

I changed the branch to master, when I tried to go back to my dev-branch it gave me an error

$ git checkout dev-branch
wp-content/plugins/advanced-custom-fields-pro/admin/views/settings-export.php needs merge
wp-content/plugins/advanced-custom-fields-pro/assets/inc/select2/select2_locale_no.js needs merge
error: you need to resolve your current index first

I poked around a bit on the net, and finally found a way out of my problem. I ended up doing the following. I rolled back the merge that I was trying to do with:

git reset --merge

This will remove your merge, and if this is not for you, you should resolve those merge conflicts.

After this I was able to checkout my dev-branch

What I did next was to merge my dev-branch into master but exactly keep the versions of the files in the dev-branch. That was done the following way.

# Switch to the topic branch:
git checkout dev-branch

# Create a merge commit, which looks as if it's merging in from master, but is
# actually discarding everything from the master branch and keeping everything
# from dev-branch:
git merge -s ours master

# Switch back to the master branch:
git checkout master

# Merge the dev-branch into master - this should now be a fast-forward
# that leaves you with master exactly as dev-branch was:
git merge dev-branch

This solved the problem I had, and I hope this will help you out as well.

Want to learn more about git and branches – checkout these articles:
A successful Git branching model
Git Branching – Basic Branching and Merging

Advertisements

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

Subscribe for updates

Enter your email address to subscribe to receive notifications of new content by email.

Join 5,882 other subscribers

Advertisements