问题描述
的答案围绕 .gitignore
在Stackoverflow上,仍然没有找到答案:
我有一个现有的git项目,它们都有一个 readme.md
和一个 sample_folder /
,都在顶层。一般来说,我想从我的git(集线器)存储库中删除这些。但我想忽略它们,也就是说,阻止它们在某个克隆的本地存储库中,即在部署机器上被阻止。
.gitignore
我明白,只是关于忽略未提交的文件?坦率地说,我没有发现任何隐藏的东西(从拉+提交)已经 承诺的东西...
在Perforce我会简单地将它从相应的'客户端规格'中排除(这非常接近本地克隆的回购):
/ / whatever / myProject
- // whatever / myProject / readme.md
- // whatever / myProject / sample_folder
当然,我可以解决第二个分支,我只需删除自述文件和整个示例文件夹。但是,我将不得不继续合并来自'开发'的每一个小小的修复。这是一些东西,我宁愿避免......我宁愿在一个(被追踪的)分支上使用本地异常。
另外,我认为 git rm --cached
每当我提交时(这可能会发生,然后从我的'部署回购')... 也许我得到的问题是错误的,但是不会解决您的问题?
git rm --cached readme.md sample_folder / *
echoreadme.md>> .gitignore
echosample_folder / *>> .gitignore
git commit -am未跟踪某些文件
There are plenty of answers around .gitignore
on Stackoverflow, still I haven't found an answer:
I have an existing git project, with a readme.md
and a sample_folder/
, both on top-level. I do want to remove these from my git(hub) repository in general. But I would like to ignore them, that is, preventing them to be pulled at all, in a certain cloned local repository, i.e. on a deployment machine.
.gitignore
I understand, is only about ignoring non-committed files? Frankly, I don't find anything around hiding (from pull+commit) stuff that already is committed...
In the days of Perforce I would simple exclude it from the respective 'client spec' (which is pretty close to a locally cloned repo):
//whatever/myProject
-//whatever/myProject/readme.md
-//whatever/myProject/sample_folder
Sure, I could settle for a second branch where I simply delete readme and the entire sample folder. But then, I would have to keep merging over every tiny fix from 'develop'. Which is something, I would rather avoid... I'd rather prefer a local 'exception' over a (tracked) branch.
Also, I think git rm --cached
whenever I do commits (which may also happen now and then from my 'deployment repo')...
Perhaps I got the question wrong, but wouldn't the following solve your problem?
git rm --cached readme.md sample_folder/*
echo "readme.md" >>.gitignore
echo "sample_folder/*" >>.gitignore
git commit -am "Untracked some files"
这篇关于如何忽略git中现有的,提交的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!