4

Similar questions have been asked here, but I believe this particular one hasn't.

I have a file params.dat that stores some parameter values for my code.

This file is constantly changing, since I change the parameter values often, so I added a static version of it into my repo at home along with the rest of the code, and then ignored it with:

git update-index --assume-unchanged params.dat

Everything works fine, except when I have to make some change to the static version of the file (which happens no so often). What I do is, first un-ignore it with:

git update-index --no-assume-unchanged params.dat

then make the necessary changes, commit and push them to Github and finally ignore the file again.

This works flawlessly with my main repo, but when I try to git pull from the repo I keep at work, I get:

error: Your local changes to the following files would be overwritten by merge:
    params.dat
Please, commit your changes or stash them before you can merge.
Aborting

I tried, as explained here, to do:

git fetch --all
git reset --hard origin/master

but I get:

error: Entry 'params.dat' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'origin/master'.

I also tried:

git stash
git merge origin/master
git stash pop

as stated here, but after git stash I get:

No hay cambios locales que guardar

(roughly translates to "No local changes to save")

To make things clear: I am not interested in keeping any changes on the params.dat file on the repo I keep at my work. I just want it to be an exact copy of whatever I pushed last to Github from home.

What is the appropriate way to handle this?

Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404
  • Possible duplicate of [How do I resolve git saying "Commit your changes or stash them before you can merge"?](http://stackoverflow.com/questions/15745045/how-do-i-resolve-git-saying-commit-your-changes-or-stash-them-before-you-can-me) – kenorb Jul 24 '16 at 12:15

2 Answers2

4

"No local changes to save" in this case means git stash doesn't see local changes in params.dat as it is assumed to be unchanged.

Before pulling, you have to make local changes visible, and get rid of them in params.dat file if any:

$ git update-index --no-assume-unchanged params.dat
$ git checkout -- params.dat
$ git pull
$ git update-index --assume-unchanged params.dat

If there are not-commited local changes in other files you are interested in, use stashing to keep them and restore after pulling:

$ git update-index --no-assume-unchanged params.dat
$ git checkout -- params.dat
$ git stash
$ git pull
$ git stash pop
$ git update-index --assume-unchanged params.dat
Stas
  • 11,571
  • 9
  • 40
  • 58
  • Won't this keep the changes to `params.dat`? The OP said he didn't want to "keep *any* changes on `params.dat`". – wspurgin Oct 27 '15 at 19:43
  • @wspurgin hmm... I see `git stash pop` in the question, so added it... Let me re-read it) – Stas Oct 27 '15 at 19:47
  • maybe `git update-index --no-assume-unchanged params.dat` then `git checkout params.data`? Then pulling and updating the index? – wspurgin Oct 27 '15 at 19:49
  • @wspurgin exactly! Thanks for pointing this out... I've missed that he is not interested in local changes... so no need in stashing there. – Stas Oct 27 '15 at 19:57
  • glad I could help. Cheers :) – wspurgin Oct 27 '15 at 20:02
  • Thank you @Stas, as soon as I can I'll try it at work and mark it as accepted if it works, or comment here if it doesn't. – Gabriel Oct 28 '15 at 00:28
  • Just tried it, your answer worked perfectly. Thank you @Stas! – Gabriel Oct 30 '15 at 18:33
  • 1
    @Gabriel You're welcome! Also, it may be convenient in your case to use `git pull --rebase` instead of `git pull` if you have new local (not pushed yet) commits. It will rebase them on top of commits pulled from upstream, instead of creating a merge commit. – Stas Oct 30 '15 at 18:42
1

I tried all the aforementioned steps, but it didn't work for me.

After hours online, I found out somewhere that you can just rename that file then do your pull or reset or rebase.

This will pull the remote file for you (recreate the renamed file).

Now you can delete the renamed file and life goes on.

Kaka Ruto
  • 4,581
  • 1
  • 31
  • 39