5

We have a shared directory (call it /shared) that we keep automatically up to date with our master git branch, by running these commands whenever there is a push to master:

   git reset --hard HEAD
   git clean -f -d
   git pull

This works for the most part. However there is a directory /shared/media that we don't want to be touched, even though there is a "media" symlink checked into git.

I've added "media" to .git/info/exclude, but regardless, "git reset --hard HEAD" removes /shared/media and replaces it with the checked in symlink.

Is there any way to get "git reset --hard HEAD" to leave this directory alone, other than e.g. by moving it out of the way beforehand and restoring it afterwards?

Jonathan Swartz
  • 1,913
  • 2
  • 17
  • 28
  • `.gitignore` should work just as well as `.git/info/exclude`, and it is committed to git, this being available to all developers. Any reason why are you changing git repo internals instead? – Alexander Gladysh Nov 07 '11 at 21:49
  • @AlexanderGladysh: `.git/info/exclude` is meant to be user editable, it isn't a git internal. It is a legitimate way of ignoring paths that are specific to one particular clone. – CB Bailey Nov 07 '11 at 22:35
  • @CharlesBailey: Your own answer to this question suggests that committing this info to git is usually more useful. But I agree, that for the limited number of use cases (not sure which) it may make sense to add ignored stuff only to `.git/info/exclude`. – Alexander Gladysh Nov 07 '11 at 23:07
  • @AlexanderGladysh: I have a "media" symlink checked in, so normally I don't want to ignore it. I only wanted to ignore it in this *particular* clone, hence the change to .git/info/exclude. – Jonathan Swartz Nov 08 '11 at 00:33
  • @JonathanSwartz: OK, that's a valid one. – Alexander Gladysh Nov 08 '11 at 01:06

2 Answers2

8

git update-index --skip-worktree <file> should do the trick (see similar question: git update-index --assume-unchanged and git reset)

Community
  • 1
  • 1
Russell Davis
  • 8,319
  • 4
  • 40
  • 41
1

You can't ignore a path that has actual content stored against it in a git repository. Git will honour changes to the tracked tree. Ignoring only affects attempts to start tracking new content, requiring an add -f to actually store new content.

This holds however, if you ignore a path with .gitignore, .git/info/exclude, or via a core.excludesfile configuration.

If you don't want your media directory to be removed by a hard reset, you need to remove the conflicting path from the repository. Other than explicitly resetting only other paths, there is no workaround.

wesinat0r
  • 121
  • 8
CB Bailey
  • 755,051
  • 104
  • 632
  • 656