Solution:
Your error seems at the time you have modified a file and the branch that you are switching to has changes for this file too (from advanced merge point).
Your options, as I view it, are - commit, and then amend this commit with extra changes (you can modify commits in git, as long as they're not impulse); or - use stash:
git stash save your-file-name
git checkout master
# do whatever you had to do with master
git checkout staging
git stash pop
git stash save
will make stash that conceives your changes, however it isn't associated with any commit or even branch. git stash pop
will employ advanced stash entry to your current branch, restoring saved changes and removing it from stash.
I encountered the similar problem and solved it by
git checkout -f branch
and its specification is more clear.
-f, --force
At the time switching branches, proceed even in case the index or the performing tree differs from HEAD. This is employed to throw away local changes.
At the time checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.
You can force checkout your branch, in case you do not want to commit your local changes.
git checkout -f branch_name
I encountered the similar problem and solved it by
git checkout -f branch
Definitely, be careful with the -f
switch. You will miss out any uncommitted changes in case you employ the -f
switch. While there may be some use instances where it is useful to employ -f
, in most instances, you may need to stash
your changes and then switch
branches. The stashing
process is stated above.
Alright with the assistance of the other two answers I've come up with a direct solution:
git checkout HEAD^ file/to/overwrite
git pull
This performs for me to override all local changes and does not need an identity:
git reset --hard
git pull
Here is a solution that throws away staged changes:
git reset file/to/overwrite
git checkout file/to/overwrite
You can either commit your changes before you do the merge, or you stash them:
git stash save
git merge origin/master
git stash pop