A brief on ignoring files. I wish it was as simple as that.
The biggest problem for me is when I want to ignore a file that was previously tracked - ignore it forever but have it not deleted when someone pulls from the remote. This is not possible unfortunately - see the comments by torek starting here.
And a git assume-unchanged vs skip-worktree post that details what happens
to an --assume-unchanged
file on pull etc. Also SO questions:
- git assume unchanged vs skip worktree - ignoring a symbolic link - see this answer for
core.sparseCheckout
- Git - Difference Between ‘assume-unchanged’ and ‘skip-worktree’
- Who touched my git assume-unchanged bit?
- Preserve git –assume-unchanged files between branch checkouts
- git stash and –skip-worktree files
- git-update-index(1) Manual Page
- and a discussion on the mailing list with Hamano: http://thread.gmane.org/gmane.comp.version-control.git/146082
- a very interesting answer explaining differences between how git expands patterns passed to it - referred to as “pathspecs” - as opposed to how shell would resolve them (globs): Git add not working with .png files?
- Finally, how to have local versions of tracked config files in git
If you want to --skip-worktree
a directory cd to the directory and issue git ls-files -z | xargs -0 git update-index --assume-unchanged
- see there for a find
alternative.
To see the files that are skipped: git ls-files -v
.
Glob patterns to regexes:
- Java: http://stackoverflow.com/questions/1247772/is-there-an-equivalent-of-java-util-regex-for-glob-type-patterns
- Python: http://stackoverflow.com/a/1555769/281545
And btw adding .“gitignore” to .gitignore works perfectly.
And git filter branch a file out: git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
Bonus: - squash last 3 commits: git reset –soft head~3 && git add -A && git commit -m “Squashed 3 last commits” - git rebase –onto - should be using it more - .gitignore Syntax: bin vs. bin/* vs. bin/** vs bin/