Reputation: 4570
(in topicBranch)
git add .
git commit -m "added new feature"
git checkout master
git merger topicBranch
gives me the following error:
error: Your local changes to the following files would be overwritten by merge:
Looking at the log, the file in question is just some breakpoint related file buried deeply within my xcuserdata
directory. My thinking was to run git rm --cached path/to/that/file
and the problematic file would be removed from the index and git would have no problems with a merge. But it still fails.
My questions are A) how can I get the merge to run? B) given that git uses the "index" as its main area of interest, why wouldn't removing the problematic file from the index allow for a merge?
Upvotes: 2
Views: 984
Reputation: 1323223
You should not remove that file from the index, but reset it or stash it (meaning remove the local changes: the file is still needed in the index):
git stash
# or
git checkout -- your/file # overwrite any local change
# or, nuclear option
git reset --hard
If stashed, the normal workflow is to git stash pop
after the merge.
(I actually prefer pull.rebase + rebase.autostash, that way git does stash for me on git pull)
Uncommited changes that are stored in the stash can be taken out and applied to the original branch and other branches as well.
(source: "Git Beginners Guide: Switching branches")
This is where the git stash command comes into play. Like
git reset --hard
, it gives you a clean working directory, but it also records your incomplete changes internally.
After fixing the critical bug, you can re-apply these changes and pick up where you left off. You can think ofgit stash
as a "pause button" for your in-progress work.
(source: "Quick Tip: Leveraging the Power of Git Stash")
Upvotes: 4