我克隆了一个包含一些.csproj文件的项目。我不需要/喜欢我的本地csproj文件被Git跟踪(或在创建补丁时被提起),但很明显,项目中需要这些文件。

我已经将*.csproj添加到我的LOCAL.gitignore中,但文件已经在repo中。

当我键入gitstatus时,它显示了我对csproj的更改,我对跟踪或提交补丁程序不感兴趣。

如何从我的个人存储库中删除这些文件的“跟踪”(但将它们保存在源中,以便我可以使用它们),以便我在执行状态(或创建补丁)时不会看到更改?

是否有正确/规范的方法来处理这种情况?


当前回答

为了节省一些时间,您添加到.gitignore中的规则可以用于删除多个文件/文件夹,即。

git rm--缓存的app/**/*.xml

or

git rm--缓存的-r app/widgets/yourfolder/

电子交易中心。

其他回答

忘了你的gitignore?

如果您在本地拥有整个项目,但忘记添加git-ignore,现在正在跟踪一些不必要的文件,请使用此命令删除所有内容

git rm --cached -r .

确保您处于项目的根位置。

然后你可以像往常一样

Add

git add .

犯罪

git commit -m 'removed all and added with git ignore'

Push

git push origin master

结论

希望这能帮助那些不得不对自己的.git进行更改的人。

它会删除整个缓存看看你的.gitignore添加要跟踪的文件推送至您的回购

只需调用git-rm-缓存在要从修订控制中删除的每个文件上就可以了。只要本地忽略模式正确,您就不会在git状态的输出中看到这些文件。

请注意,此解决方案从存储库中删除文件,因此所有开发人员都需要维护自己的本地(非版本控制)文件副本

要防止git检测到这些文件中的更改,还应使用以下命令:

git update-index --assume-unchanged [path]

你可能想做什么:(从下面@Ryan Taylor回答)

这是为了告诉git您想要自己的独立版本的文件或文件夹。例如,您不想覆盖(或删除)生产/登台配置文件。git更新索引--跳过工作树<路径名>

完整答案在以下URL中:http://source.kohlerville.com/2009/02/untrack-files-in-git/

我假设你试图从gittacking中删除一个文件。为此,我建议使用以下命令。

git更新索引--假设未更改

Ex-git更新索引——假设没有变化。gitignore.deide/compiler.xml

将.gitignore应用于当前/未来

此方法应用标准的.gitignore行为,不需要手动指定需要忽略的文件。无法再使用--exclude-from=.gitignore:/-以下是更新的方法:一般建议:从一个干净的repo开始-所有内容都已提交,工作目录或索引中没有挂起的内容,并进行备份!

#commit up-to-date .gitignore (if not already existing)
#this command must be run on each branch
git add .gitignore
git commit -m "Create .gitignore"

#apply standard git ignore behavior only to current index, not working directory (--cached)
#if this command returns nothing, ensure /.git/info/exclude AND/OR .gitignore exist
#this command must be run on each branch
git ls-files -z --ignored --exclude-standard | xargs -0 git rm --cached

#optionally add anything to the index that was previously ignored but now shouldn't be:
git add *

#commit again
#optionally use the --amend flag to merge this commit with the previous one instead of creating 2 commits.

git commit -m "re-applied modified .gitignore"

#other devs who pull after this commit is pushed will see the  newly-.gitignored files DELETED

如果您还需要从分支的提交历史记录中清除新忽略的文件,或者如果您不希望从将来的拉取中删除新忽略的文档,请参阅此答案。

在搜索了很长时间之后,找到一种方法。在android studio项目中,在.gitconfig.like中别名一个git命令,在签出分支之前还原配置文件,然后跳过它,签出分支之后使用sed将配置文件更改为我的本地配置。签出和修改属性=!git update-index--no-skip-worktree local.properties&&git checkout local.pproperties&&git-checkout$1&&git update-index--skip-worktree本地.properties&&sed-i''s/.*sdk.dir.*/sdk.dir=\\/Users\\/run\\/Library\\/Android\\/sdk/g'local.properties&&: