Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git reset --hard seems to ignore .git/info/exclude

Tags:

git

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?

like image 429
Jonathan Swartz Avatar asked Nov 07 '11 20:11

Jonathan Swartz


People also ask

Does git reset hard remove ignored files?

git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone.

Will reset hard remove untracked files?

git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !

What is git info exclude?

git/info/exclude . This file is your own gitignore inside your local git folder, which means is not going to be committed or shared with anyone else. You can basically edit this file and stop tracking any (untracked) file. Here's what the official Git - gitignore Documentation says about this file.


1 Answers

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

like image 127
Russell Davis Avatar answered Sep 28 '22 00:09

Russell Davis