问题
Is it possible to have repo specific .gitignore files? Eg:
[origin] .gitignore:
- foo1.*
- foo2.*
[another] .gitignore:
- bar1.*
- bar2.*
The purpose behind this is that we deploy using git on to a managed cloud service and we'd like to keep dev files in version control but not push them to a repo.
回答1:
Yes, you can put per repository ignore patterns in .git/info/exclude
in each repository.
(Note, this only affects what is ignored in each repository, it won't affect files that you actively place under source control and the push. I'm not completely clear on your desired use case.)
回答2:
Yes you can, just can't have them in the same folder. If you create a new folder, day "deploy" and publish your deploy data there, it will use the .gitignore in that folder (not the root one).
回答3:
You could probably do this using git hooks (the scripts in .git). post-checkout sounds good.
回答4:
My Situation:
Having a file named
alex.todo
which contains my personal notes about the project. I have two remote repo to push(origin
andalex
). One for sharing the code with other developers(I use.gitignore
to exclude thealex.todo
file), one just for backing up this project which is ok to preserve thealex.todo
file.
My final solution:
Using a temp branch to push the
alex.todo
to the backup repo.
# Step 1
git checkout -b alex # 'alex' or whatever branch name you prefer
# Step 2
# now you can edit your .gitignore to include your 'alex.todo' file
# Step 3
git add . && git commit -m 'commit some ignore files'
git push alex alex:master # git push <remote> <local branch name>:<remote branch to push into>
# Step 4
git checkout master # return to branch master and do any editings(commits)
# Step 5
# make sure branch alex is in sync with master whenever you want to push the project to the backup repo
git checkout alex
git merge master # .gitignore will not automatically be included for commit unless specifically added
# now you can repeat step 3 to push the project to the backup repo
来源:https://stackoverflow.com/questions/7965431/repo-specific-ignore-files-in-git