2

I have repository my team works on in which there are some files that are tracked but may be changed locally like .exe file which is an effect of compilation but should be checked in only when release is done. Another is makefile.mk in which I set some local option and rarely make changes I need to commit. Usually this file is different from repository version ant this is OK. So these files are tracked, cannot be put into .gitignore but make git pull origin cry for overwriting changes to these files (error: Your local changes to the following files would be overwritten by merge). I tried to put *.exe~ into .git/info/exclude (as well as the .mk) and run git update-index --no-assume-unchanged that.exe so git status no longer shows them but pulling still fails, even with -f. I read somewhere to use git update-index --skip-worktree an I tried. Now no one knows how to update my repo.

  • How can I keep modified files which are tracked and make GIT ignore their changes locally?
  • How could I repair my repository without cloning it (I'd miss some config files for example)?
Tomator
  • 81
  • 8

2 Answers2

0

How can I keep modified files which are tracked and make GIT ignore their changes locally?

Git cannot track and ignore a file on the same time; it doesn't make any sense.

Remove the files from Git (git rm --cached that.exe makefile.mk), add their names to .gitignore and commit.

Make a copy of makefile.mk (let's say makefile.mk.example) provide sensible defaults for the values that change from one development environment to another and add it to the repository.

Document this change to let any developer know how to get their own makefile.mk when they clone the repo.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • 1
    Decisions were made on 'higher level' to have exe in repo, so it cannot be put in global `.gitignore` and removed from repository. ignoring in locally would really help; too bad GIT cannot do such a thing. – Tomator Feb 13 '18 at 11:41
  • You can use the same strategy for the exe file. Use a different name (and ignore it) for the exe file generated locally on each build and update the original file only when you need to put it in the repo. Or rename the file from the repo and, again, update it locally only when you need to commit it. – axiac Feb 13 '18 at 11:45
  • 1
    Git (or any other VCS) working as you want/need defeats the purpose of source control. – axiac Feb 13 '18 at 11:47
0

for your first question, you could use the command.

git rm --cached <filename>

rm is for removal.

and for second question you can find the answer here

Kunal Pal
  • 545
  • 8
  • 21
  • Thanks. This doesn't help for the main question but removing files from cache followed by `git reset branch --hard` finally let the `git pull` to do the job! – Tomator Feb 13 '18 at 11:54