1

The following situation:

We have some local config file in the GIT which should be removed.

If we just do a git rm and add it to the .gitignore, the file will be deleted on each developer's computer.

But we want to avoid that - the file should be no longer the git repository, but it also should not be deleted on a pull/merge.

Is this possible and how?

Alex
  • 32,506
  • 16
  • 106
  • 171
  • @JamesMcLaughlin I would not consider this a duplicate of that question. That one was asking about removing a file, but keeping it in the current working tree. This one is asking about keeping it in the working tree for any other copies of the repository, a much more difficult thing which the accepted answer for the other question would not work. – qqx Mar 06 '13 at 13:50

3 Answers3

1

git rm --cached keeps local files but removes them from the repo.

David Haynes
  • 933
  • 5
  • 14
  • 1
    But still when another developer does a pull, he will get this "delete command" and git will delete his file. – Alex Mar 06 '13 at 13:27
1

There isn't a way to do precisely what you're looking for. But the following may work for you.

In a comment on a now deleted answer you stated that your goal is to replace the to-be-deleted file with a template for that file. If that template file is created by the same commit in which the old file is removed, and the files are similar enough git would see detect that as a rename (this is actually what git mv does).

When other developers then attempt to merge that change into their repository, their copy would be renamed rather than deleted. If, as is likely, they had local changes to the file that would prevent that commit from being merged. At that point they could simply copy their version of the file to a temporary name and use git checkout HEAD <thefile> to discard their changes to the original. This would allow the merge to proceed, including the rename. After that they could move the temporary copy back to the original name.

This does require some work in each non-bare copy of that repository, but in no case should it result in work being deleted.

qqx
  • 18,947
  • 4
  • 64
  • 68
0

1) Let's say you're working in the master branch:

git rm dont-track-me.txt
git commit
git push origin master

2) Now on the developer's box:

git pull  # yep, this will delete the file
git checkout HEAD^ dont-track-me.txt
git reset # prevents restaging the file in the index

'dont-track-me.txt' is now present as an untracked file in the developer's working tree. This does assume that no other activity happens between steps (1) and (2); otherwise some more fiddling may be required.

gcbenison
  • 11,723
  • 4
  • 44
  • 82