Reputation: 42329
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?
Upvotes: 4
Views: 9403
Reputation: 5125
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.
Upvotes: 1
Reputation: 11761
"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
Upvotes: 4