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?
git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone.
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 !
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.
git update-index --skip-worktree <file>
should do the trick (see similar question: git update-index --assume-unchanged and git reset)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With