简体   繁体   English

如何使GIT在本地忽略跟踪的文件?

[英]How to make GIT ignore tracked file locally?

I have repository my team works on in which there are some files that are tracked but may be changed locally like .exe file which is an effect of compilation but should be checked in only when release is done. 我的团队在仓库中工作,其中跟踪了一些文件,但可能会在本地进行更改,例如.exe文件,这是编译的结果,但只有在完成发行后才应签入。 Another is makefile.mk in which I set some local option and rarely make changes I need to commit. 另一个是makefile.mk,在其中我设置了一些本地选项,很少进行需要提交的更改。 Usually this file is different from repository version ant this is OK. 通常,此文件与存储库版本ant不同,可以。 So these files are tracked, cannot be put into .gitignore but make git pull origin cry for overwriting changes to these files ( error: Your local changes to the following files would be overwritten by merge ). 因此,将跟踪这些文件,无法将它们放入.gitignore而会使git pull origin因覆盖这些文件的更改而哭泣( 错误:对以下文件的本地更改将被merge覆盖 )。 I tried to put *.exe~ into .git/info/exclude (as well as the .mk) and run git update-index --no-assume-unchanged that.exe so git status no longer shows them but pulling still fails, even with -f . 我试图将*.exe~放入.git/info/exclude (以及.mk)并运行git update-index --no-assume-unchanged that.exe所以git status不再显示它们,但是拉取仍然失败,即使使用-f I read somewhere to use git update-index --skip-worktree an I tried. 我读过某处使用git update-index --skip-worktree我尝试了。 Now no one knows how to update my repo. 现在没人知道如何更新我的仓库。

  • How can I keep modified files which are tracked and make GIT ignore their changes locally? 如何保留已跟踪的修改文件并使GIT在本地忽略它们的更改?
  • How could I repair my repository without cloning it (I'd miss some config files for example)? 我该如何修复我的存储库而不克隆它(例如,我会错过一些配置文件)?

How can I keep modified files which are tracked and make GIT ignore their changes locally? 如何保留已跟踪的修改文件并使GIT在本地忽略它们的更改?

Git cannot track and ignore a file on the same time; Git无法同时跟踪和忽略文件。 it doesn't make any sense. 这没有任何意义。

Remove the files from Git ( git rm --cached that.exe makefile.mk ), add their names to .gitignore and commit. 从Git中删除文件( git rm --cached that.exe makefile.mk ),将它们的名称添加到.gitignore并提交。

Make a copy of makefile.mk (let's say makefile.mk.example ) provide sensible defaults for the values that change from one development environment to another and add it to the repository. 制作makefile.mk的副本(例如makefile.mk.example ),为从一个开发环境更改为另一个开发环境的值提供合理的默认值,并将其添加到存储库中。

Document this change to let any developer know how to get their own makefile.mk when they clone the repo. 记录此更改,以使任何开发人员在克隆存储库时都知道如何获取自己的makefile.mk

for your first question, you could use the command. 对于第一个问题,您可以使用命令。

git rm --cached <filename>

rm is for removal. rm用于删除。

and for second question you can find the answer here 对于第二个问题,您可以在这里找到答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM