Reputation: 1010
I'm having a git problem where I want to merge a branch into master but it's refusing to merge because it thinks I have local changes to a file. Doing status shows no changes and diffing the files produces nothing. Here's the terminal output:
$ git checkout ProductsAndContents
Switched to branch 'ProductsAndContents'
$ git status
# On branch ProductsAndContents
nothing to commit (working directory clean)
$ git checkout master
Switched to branch 'master'
$ git status
# On branch master
nothing to commit (working directory clean)
$ git merge ProductsAndContents
error: Your local changes to the following files would be overwritten by merge:
tests/unit/src/models/BrandTests.js
Please, commit your changes or stash them before you can merge.
Aborting
Any help or suggestions would be most appreciated!
Upvotes: 9
Views: 2890
Reputation: 1010
Thanks to Andrew Myers' comment on my initial question, I discovered setting core.trustctime
to false
solved the problem.
git config core.trustctime false
Something about mismatching inode change times. I'm guessing this is because the repo is sitting on a fileshare on a machine with a different file system from the one I'm using.
Thanks for all the suggestions!
Upvotes: 3
Reputation: 62519
I would guess this is your scenario:
$ git checkout ProductsAndContents
Switched to branch 'ProductsAndContents'
Branch ProductsAndContents
contains the file tests/unit/src/models/BrandTests.js
, so the above checkout
creates it and/or makes sure it's up to date with the specific commit requested.
$ git status
# On branch ProductsAndContents
nothing to commit (working directory clean)
You haven't made any changes, and started with a clean working directory, so this is good.
$ git checkout master
Switched to branch 'master'
This makes sure all files contained in the latest commit on master
are up to date in the working directory. However, it does not remove or update files that are not contained in master
, or that are ignored. Here I assume master
for whatever reason does not currently include the file in question.
$ git status
# On branch master
nothing to commit (working directory clean)
Again, you've made no modifications. The fact that the file in question is not mentioned here as an untracked file probably means it's ignored (either in .gitignore
or in .git/info/exclude
). master
doesn't contain the file so it's not concerned that it exists.
$ git merge ProductsAndContents
error: Your local changes to the following files would be overwritten by merge:
tests/unit/src/models/BrandTests.js
Please, commit your changes or stash them before you can merge.
Aborting
Here, your attempt to merge in the other branch wants to introduce a file that master
currently doesn't have, which is normally fine. However, that file exists in your working directory, and git
doesn't want to trash something that it's not sure is preserved in the repository. As suggested elsewhere, you could (assuming you know it's safe) simply remove that file and re-try the merge.
With the information you have given, I'm not 100% sure that's what you have here; you could run these two commands to check for that condition, though:
git ls-files master -- tests/unit/src/models/BrandTests.js
git ls-files ProductsAndContents -- tests/unit/src/models/BrandTests.js
If my guess is right, the first command will not show that the file exists, while the second will. Then check .gitignore
and .git/info/exclude
to see if it's being ignored (for .gitignore
, you may need to check the version that exists on each of the two branches).
Upvotes: 1
Reputation: 21119
Well, if you're confident you won't loose any work, try the following:
rm tests/unit/src/models/BrandTests.js
git checkout -- tests/unit/src/models/BrandTests.js
That should reset any mechanism that made it think it had changes. If it doesn't work, have others that might.
Upvotes: 2
Reputation: 1963
Just because each branch has nothing to commit does not mean that they are the same. I would be interested in viewing the differences between the two files using
git diff
You can revert to the revision that has been commited to the repo using
git checkout -- tests/unit/src/models/BrandTests.js
Upvotes: -2