43

Here is the scenario:

In my working directory, I have a number of files (let's call them A,B,C) that I've edited. I then ran git update-index --assume-unchanged on those files. Now git status returns blank. Good.

Now, if I do a git reset --hard, the contents of the files A,B, and C, revert back to the contents before I've edited them and "assume-unchanged" them.

Is there a way to stop git from actually reverting files A,B, and C, and simply ignore them?

Thanks,

Ken

Ken Hirakawa
  • 7,831
  • 10
  • 38
  • 49
  • Hm, good question. I don't know the answer, but maybe you can write a little script that does a checkout on those three files, and then use it as a post-action hook on actions like reset that would cause them to be overwritten. – Tyler May 24 '11 at 01:39

3 Answers3

50

You can do:

git update-index --skip-worktree A
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Nice! That works. The only issue I have now is that the git plugin for eclipse (egit) can't handle --skip-worktree... Grr. – Ken Hirakawa May 24 '11 at 16:39
  • Be aware that if you have [sparse checkouts](https://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html#_sparse_checkout) enabled, this setting will be overwritten and you should use the `sparse-checkout` file to ignore the files in question. – AndreKR Jun 12 '13 at 20:03
  • Isn't using `sparse-checkout` file result in not just ignoring but also auto-removing these files? – Powerman Jan 21 '15 at 12:24
1

You could use

$ git stash
$ git reset --hard
$ git stash pop
ViToni
  • 882
  • 9
  • 12
1

You need to add a .gitignore file entry for those files if you want to ignore them. Add just the .gitignore file, commit it and you will now ignore any changes to them.

However, I think you need to tell us why you are doing it, what's the contents of the files, the nature of them (are they artifacts?) - then you'll get the proper answer.

Also, update-index with the assume-unchanged is meant to be used to increase performance if your tree on your OS's file system takes a long time to gather changes for a particular path. I would not recommend using it in your case unless you are ignoring those files due to lengthy git status or git diff or other command execution times.

user229044
  • 232,980
  • 40
  • 330
  • 338
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • 2
    Files A,B and C are actually unix symlink files which were checked out into a windows system. Since windows can't work with unix symlinks, git converts them into plain text files. My script then runs and finds these 'dummy' files and replaces them with windows symlinks. If I do a git status here, then I have A,B and C in the modified state. Instead, however, I want changes to A,B,C ignored pretty much forever. git update-index --assume-unchanged works great, unless git reset is issued. Hence the question. Hope this clarifies things a bit =) – Ken Hirakawa May 24 '11 at 16:33
  • @KenHirakawa You want `smudge` and `clean`. See tutorial here: https://www.bignerdranch.com/blog/git-smudge-and-clean-filters-making-changes-so-you-dont-have-to/. If you update your question to reflect what you're trying to do, I can leave an answer. – DylanYoung Jul 19 '20 at 23:23