8

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!

Mark Stickley
  • 1,000
  • 1
  • 12
  • 28

4 Answers4

3

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!

Mark Stickley
  • 1,000
  • 1
  • 12
  • 28
1

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.

Trevor Norris
  • 20,499
  • 4
  • 26
  • 28
  • Thanks for the suggestion Trev! I tried that but unfortunately it still gives the same error. So strange... – Mark Stickley Mar 04 '13 at 12:54
  • I also encountered this, but it appears that `git stash` would refuse to see a file as modified. I manually backed it up, checked it out, and compared the changes by hand. There's got to be a better way... – Paul Lammertsma Jun 02 '14 at 15:37
  • @PaulLammertsma Don't forget that a `stash` is nothing more than another commit and has its own hash. You can operate on it as you would any other commit. Which leaves many other options. I had just found the above to be the quickest. – Trevor Norris Jun 02 '14 at 22:20
  • @TrevNorris That's the weird thing; everything was committed and well. It took deleting the file, checking it out again and replying the changes for it to get sorted out. – Paul Lammertsma Jun 02 '14 at 22:30
1

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).

twalberg
  • 59,951
  • 11
  • 89
  • 84
  • Thanks! Unfortunately the file is in both branches and not in .gitignore or .git/info/exclude. Here's the output: $ git ls-files master -- tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js $ git ls-files ProductsAndContents -- tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js – Mark Stickley Mar 04 '13 at 13:01
-2

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
Gardner Bickford
  • 1,934
  • 1
  • 17
  • 25
  • 3
    `Please, commit your changes or stash them before you can merge.` implies uncommitted changes, not committed diffs between branches – Jonathan Wakely Mar 01 '13 at 19:18
  • There are really no changes to commit, and no untracked files. As I mentioned, diffing produces zero output. I'm baffled. – Mark Stickley Mar 04 '13 at 12:55