Git:只在本地回购中找到一个文件并将其保存在远程回购中 [英] Git: untrack a file in local repo only and keep it in the remote repo
问题描述
我有一个NetBeans文件nbproject / project.properties,它始终显示在未针对提交进行的更改部分中(当我执行git状态时)。我怎么能把它移动到Untracked files部分(没有将它添加到.gitignore中)?我试过这个命令 git rm --cached
但是发生了什么事情是文件在我的本地仓库中显示为未跟踪并在远程仓库中被删除,但我想要的是保留它在远程和未追踪的只有在本地回购。 你可以更新您的索引:
cd / root / folder / of / your / repo
git update-index --assume-unchanged nbproject / project.properties
,并确保它不会在您当前的回购中显示为更新。
这意味着它不会被推动,但它是仍然存在于索引中。
(并且可以在本地工作树中随意修改)。
$ b $ hr
- 可恢复该状态(来自 git-ready ):
git update-index --no-assume-unchanged
- (来自 Gabe Kopley 的 - ul>
git ls-files -v | grep'^ h'
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.
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 been 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 update-index --no-assume-unchanged
- to see all assume unchanged files (from Gabe Kopley's comment)
git ls-files -v | grep '^h '
这篇关于Git:只在本地回购中找到一个文件并将其保存在远程回购中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!