取消跟踪 git 上的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17141050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Untrack all files on git
提问by Airhogs777
In the move from C9 to hosting on my Macbook via SSH, I've had to re-download Kohana and change some other things just to get my site working; I don't want those to be committed. Is there any way to untrack all tracked files so only future changes are committed? Or is there something else I should be doing?
在从 C9 迁移到通过 SSH 托管在我的 Macbook 上的过程中,我不得不重新下载 Kohana 并更改其他一些内容,以便让我的网站正常工作;我不希望那些被提交。有没有办法取消跟踪所有跟踪的文件,以便只提交未来的更改?或者还有什么我应该做的吗?
I'm on a Macbook running Mountain Lion with Apache and PHP turned on.
我在一台 Macbook 上运行 Mountain Lion,并打开了 Apache 和 PHP。
回答by sinhayash
git rm --cached File
git rm --cached File
Will delete the file in the index, so it will no longer be tracked, but won't physically delete it. This will untrack the file only for current branch
将删除索引中的文件,因此将不再对其进行跟踪,但不会物理删除它。这将仅为当前分支取消跟踪文件
[OR]
[或者]
Use this git command. After you do this, git stops checking the file for possible modifications.
使用这个 git 命令。执行此操作后,git 将停止检查文件以进行可能的修改。
git update-index --assume-unchanged <filename>
At any time, you can track again by setting --no-assume-unchaged
flag
在任何时候,您都可以通过设置--no-assume-unchaged
标志再次跟踪
git update-index --no-assume-unchanged <filename>
But these command do not affect the remote repository.
但是这些命令不会影响远程存储库。
回答by VonC
Even simpler:
更简单:
cd /root/directory/of/your/local/repo
git rm --cached -r .
^^^
(space - dot)
Even even simpler:
甚至更简单:
git clone url/for/Kohana /different/local/path
回答by Remixed123
I'm not exactly sure what you mean by "untrack all tracked files so only future changes are committed". As you need to track files so they can be committed.
我不太确定您所说的“取消跟踪所有跟踪的文件,以便仅提交未来的更改”是什么意思。因为您需要跟踪文件以便提交。
If all you just want to do is not track Kohana and the other downloads, then just remove them from your working directory using git rm --cached <file>
or even better create a .gitignore
file.
如果您只想做的不是跟踪 Kohana 和其他下载,那么只需使用git rm --cached <file>
或更好地创建.gitignore
文件从您的工作目录中删除它们。
There are many helpful posts on stackoverflow to assist you with creating a .gitignore
file for your project. By using this, you can exclude an entire folder easily.
stackoverflow 上有很多有用的帖子可以帮助您.gitignore
为项目创建文件。通过使用它,您可以轻松排除整个文件夹。
For Mac, it would also be helpful if you could see hidden file as the . file is hidden. This page shows you how to see hidden files on Mountain Loin - http://www.mikesel.info/show-hidden-files-mac-os-x-10-7-lion/
对于 Mac,如果您可以将隐藏文件视为 . 文件被隐藏。此页面向您展示了如何查看 Mountain Loin 上的隐藏文件 - http://www.mikesel.info/show-hidden-files-mac-os-x-10-7-lion/