I will preface this by saying that I am pretty new to git. However, this seems like a pretty straightforward scenario, and I can’t see where the problem is coming from. Here is the scenario:
I am on the master branch with some uncommitted changes that I don’t want. I need to make a separate simple change to be packaged into a patch. So I do this:
I find the hash # for the last commit to the master branch which is ffdd99afc89211e9ddc3efa3415b0adaf0076b4b.
So from the root of my repository I do:
git branch my_patch ffdd99afc89211e9ddc3efa3415b0adaf0076b4b
git checkout -f my_patch
Now I edit three files and add a fourth after which I do:
git add [path to the added file]
git status
this lists the three updated and one added file
git commit -a
git status
no changes found
git format-patch master --stdout > my_patch.patch
All is good to this point. Now I want to merge this branch back into master.
git checkout master
git status
No changes found
git merge my_patch
The output from which is:
Updating ffdd99a..e2754ca
error: Your local changes to 'Blah.cs' would be overwritten by merge.
Aborting. Please, commit your changes
or stash them before you can merge.
And now if I do git status I get a boat load of changes listed. Does this make any sense to anyone?
if you don’t want the changes when you start, do a
git reset --hard. And if there are untracked files there that you don’t want do agit clean -dfas well.As for your error message at the end, you may have an issue with casing in the path. Is this on Windows w/ msysgit?
If you are on windows, ensure you have autocrlf set to false.