暂时从 git 中取消跟踪文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6964297/
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 files from git temporarily
提问by agent.smith
I have setup a local git on my machine. When I initialized git, I added pre-compiled libs and binaries. However, now during my development I don't want to check in those files intermittently. I dont want to remove these files from repo. Is there any way to not keep a track of these files till I complete my development. (I think I can not use .gitignore as it works only for those files which are not in git. I want to temporarily disable tracking of files.)
我已经在我的机器上设置了一个本地 git。当我初始化 git 时,我添加了预编译的库和二进制文件。但是,现在在我的开发过程中,我不想间歇性地检查这些文件。我不想从 repo 中删除这些文件。在我完成开发之前,有什么方法可以不跟踪这些文件。(我想我不能使用 .gitignore,因为它只适用于那些不在 git 中的文件。我想暂时禁用文件跟踪。)
回答by Andy
git update-indexshould do what you want
git update-index应该做你想做的
This will tell git you want to start ignoring the changes to the filegit update-index --assume-unchanged path/to/file
这将告诉 git 您要开始忽略对文件的更改git update-index --assume-unchanged path/to/file
When you want to start keeping track againgit update-index --no-assume-unchanged path/to/file
当您想再次开始跟踪时git update-index --no-assume-unchanged path/to/file
回答by cajuuh
you could keep your files untracked after
你可以在之后保持你的文件不被跟踪
git rm -r --cached <file>
add your files with
添加您的文件
git add -u
them push or do whatever you want.
他们推动或做任何你想做的事。
回答by Tekkub
git rm --cached
However, you shouldn't be committing compiled binaries and external dependancies in the first place. Use a tool like Bundler to pull those in instead.
但是,您不应该首先提交已编译的二进制文件和外部依赖项。使用像 Bundler 这样的工具来代替它们。
回答by Dinesh Vaitage
Use following command to untrack files
使用以下命令取消跟踪文件
git rm --cached <file path>
回答by Eric Spreen
The git-book mentions this in section 2.4: "Undoing Things". Basically, what you have to do is reset the state of the index for some files back to the HEAD state, that is to the state of the latest checkout (or commit). This undoes staging the file to the current index. The command for this task is git reset
.[1]
git-book 在第 2.4 节:“撤消事情”中提到了这一点。基本上,您需要做的是将某些文件的索引状态重置回 HEAD 状态,即最新检出(或提交)的状态。这将撤消将文件暂存到当前索引。此任务的命令是git reset
.[1]
So, the command you have to execute is:
因此,您必须执行的命令是:
git reset HEAD /path/to/file
The newer versions of git (I believe since 1.6 or so) gives this command (and many more) as a tip when executing git status
. These versions are very user-friendly. A personal tip: if you are only staging a few files, use git add -i
. This will launch the interactive staging tool, which makes thing particularly easy. Also, I highly recommend reading the book, as it is very explicit on the use of git in practical situations.
较新版本的 git(我相信从 1.6 左右开始)将此命令(以及更多)作为执行git status
. 这些版本非常人性化。个人提示:如果您只是暂存几个文件,请使用git add -i
. 这将启动交互式暂存工具,这使事情变得特别容易。另外,我强烈推荐阅读这本书,因为它非常明确地介绍了 git 在实际情况中的使用。
回答by prime
Not an answer to the original question. But this might help someone.
不是原始问题的答案。但这可能对某人有所帮助。
To see the changes you have done (know which files are marked as --assume-unchanged)
查看您所做的更改(知道哪些文件被标记为 --assume-unchanged)
git ls-files -v
The resulted list of files will have a prefix with one character (ex : H or h) If it is a lowercase (i.e. h) then the file was marked --assume-unchanged
结果文件列表将有一个带一个字符的前缀(例如:H 或 h)如果它是小写字母(即 h),则该文件被标记为 --assume-unchanged
回答by Vraj Pandya
I am assuming that you are asking how to remove ALLthe files in the build folder or the bin folder, Rather than selecting each files separately.
我假设你是问如何删除所有这些文件在build文件夹或bin文件夹,而不是分别选择每个文件。
You can use this command:git rm -r -f /build\*
Make sure that you are in the parent directory of the build directory.
This command will, recursively "delete" all the files which are in the bin/ or build/ folders. By the word delete I mean that git will pretend that those files are "deleted" and those files will not be tracked. The git really marks those files to be in delete mode.
你可以使用这个命令:git rm -r -f /build\*
确保你在构建目录的父目录中。
此命令将递归地“删除” bin/ 或 build/ 文件夹中的所有文件。通过删除这个词,我的意思是 git 会假装这些文件被“删除”并且这些文件不会被跟踪。git 确实将这些文件标记为处于删除模式。
Do make sure that you have your .gitignore ready for upcoming commits.
Documentation : git rm
请确保您的 .gitignore 为即将到来的提交做好了准备。
文档:git rm
回答by lordharbar
git reset [file]
git 重置 [文件]
Get file back from staging area to working directory
将文件从暂存区取回工作目录
I often forget to add my node modules to the .gitignore file, this solves that problem.
我经常忘记将我的节点模块添加到 .gitignore 文件中,这解决了这个问题。
回答by divya d
To remove all Untrack files. Try this terminal command
删除所有 Untrack 文件。试试这个终端命令
git clean -fdx
回答by Vivek
This worked for me
这对我有用
git reset HEAD 'filename'
git reset HEAD '文件名'