Git:仅在本地存储库中取消跟踪文件并将其保留在远程存储库中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6791889/
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
Git: untrack a file in local repo only and keep it in the remote repo
提问by Jimmy
I have a NetBeans file "nbproject/project.properties" that always shows up in the "Changes not staged for commit"section (when I do git status). How could I move this to the Untracked files section (without adding it to .gitignore) ? I tried this command git rm --cached
but what happened is the file shows as untracked in my local repo and got removed in the remote one but what I want is to keep it in remote and untrack only in local repo.
我有一个 NetBeans 文件“nbproject/project.properties”,它总是显示在“未暂存的更改”部分(当我执行 git status 时)。我怎么能把它移到 Untracked files 部分(而不将它添加到 .gitignore)?我尝试了这个命令,git rm --cached
但发生的事情是文件在我的本地仓库中显示为未跟踪并在远程仓库中被删除,但我想要的是将它保留在远程并且仅在本地仓库中取消跟踪。
回答by VonC
You could update your index:
你可以更新你的索引:
cd /root/folder/of/your/repo
git update-index --assume-unchanged nbproject/project.properties
and make sure it never shows as "updated" in your current repo.
That means it won't ever be pushed, but it is still present in the index.
(and it can be modified at will in your local working tree).
并确保它永远不会在您当前的存储库中显示为“已更新”。
这意味着它永远不会被推送,但它仍然存在于索引中。
(并且可以在本地工作树中随意修改)。
- to revert that state (from git-ready):
- 恢复该状态(来自git-ready):
git update-index --no-assume-unchanged <file>
git update-index --no-assume-unchanged <file>
- to see all assume unchanged files (from Gabe Kopley's comment)
- 查看所有假设未更改的文件(来自Gabe Kopley的评论)
git ls-files -v | grep '^h '
git ls-files -v | grep '^h '