git 中存储库特定的忽略文件

发布于 2024-12-12 22:23:04 字数 253 浏览 3 评论 0原文

是否可以有特定于仓库的 .gitignore 文件?例如:

[来源] .gitignore:

  • foo1.*
  • foo2.*

[another] .gitignore:

  • bar1.*
  • bar2.*

其背后的目的是我们使用 git 部署到托管云服务上,并且我们希望将开发文件保留在版本控制中,但是不要将它们推送到仓库。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挖个坑埋了你 2024-12-19 22:23:04

是的,您可以将每个存储库忽略模式放入每个存储库的 .git/info/exclude 中。

(请注意,这只会影响每个存储库中忽略的内容,不会影响您主动置于源代码控制和推送下的文件。我不完全清楚您想要的用例。)

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.)

稳稳的幸福 2024-12-19 22:23:04

是的,可以,只是不能将它们放在同一个文件夹中。如果您创建一个新文件夹“deploy”并在那里发布部署数据,它将使用该文件夹(而不是根文件夹)中的 .gitignore。

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).

永不分离 2024-12-19 22:23:04

我的情况:

有一个名为alex.todo的文件,其中包含我关于该项目的个人笔记。我有两个远程存储库要推送(originalex)。一个用于与其他开发人员共享代码(我使用 .gitignore 来排除 alex.todo 文件),一个用于备份该项目,可以保留 <代码>alex.todo 文件。

我的最终解决方案:

使用临时分支将 alex.todo 推送到备份存储库。

# 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

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
姐不稀罕 2024-12-19 22:23:04

您可以使用 git hooks(.git 中的脚本)来完成此操作。结帐后听起来不错。

You could probably do this using git hooks (the scripts in .git). post-checkout sounds good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文