Repo specific ignore files in git

▼魔方 西西 提交于 2019-12-18 05:15:33

问题


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 and alex). One for sharing the code with other developers(I use .gitignore to exclude the alex.todo file), one just for backing up this project which is ok to preserve the alex.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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!