Git:忽略Commit和Pull中的特定文件 [英] Git: ignore specific file(s) both on Commit and Pull

查看:480
本文介绍了Git:忽略Commit和Pull中的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用update-index --assume-unchanged来忽略我们的ConnectionString.config,因为我在开发过程中经常更改它,并由我们的构建服务器自动生成;但是,在执行Pull / Rebase时,操作失败,因为它会在本地覆盖它,迫使我将其存储并恢复。



有没有办法忽略文件都在提交和拉?我只希望Git放弃它。

解决方案

如果您希望只发生在您的本地系统上,本地 .git / info / exclude 文件应该解决这个问题。


从上面的帖子中重新得到答案:


特定于特定存储库但不需要与其他相关存储库共享
的模式(例如,存储在存储库中的辅助
文件,但是特定于一个用户的
工作流)应该进入 $ GIT_DIR / info / exclude文件

.git / info / exclude 文件的格式与任何文件相同.gitignore文件。另一个选择是将core.excludesFile设置为包含全局模式的文件的名称。

注意,如果您已经有非稳定的更改,则编辑忽略后必须运行以下命令-patterns:

pre $ g $ update-index --assume-unchanged [< file> ...]

有关$ GIT_DIR的注意事项:这是使用 all git手册只是为了指明git仓库的路径。如果设置了环境变量,那么它将覆盖您所在的任何回购的位置,这可能不是您想要的。


I am "ignoring" our ConnectionString.config using update-index --assume-unchanged, as I change it often during development and is generated automatically by our build server anyway; however, when performing a Pull/Rebase the operation fails because it would overwrite it locally, forcing me to stash it and then restore it.

Is there a way to ignore a file both on commit and on pull? I just want Git to leave it be.

解决方案

If you want this to only happen on your local system, the local .git/info/exclude file should solve the problem.


To requote the answer from the above stack post:

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.

The .git/info/exclude file has the same format as any .gitignore file. Another option is to set core.excludesFile to the name of a file containing global patterns.

Note, if you already have unstaged changes you must run the following after editing your ignore-patterns:

git update-index --assume-unchanged [<file>...]

Note on $GIT_DIR: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.

这篇关于Git:忽略Commit和Pull中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆