如何让git忽略所有进一步编辑为单个文件而不从存储库中删除它 [英] How to tell git to ignore all further edit to a single file without removing it from the repo

查看:85
本文介绍了如何让git忽略所有进一步编辑为单个文件而不从存储库中删除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github上分支了一个项目,并开始在自己的机器上搞乱它,我想提交我在github上分叉的更改,但没有提交我对.cfg文件所做的更改,因为这包含了诸如数据库密码等的内容。

I have forked a project on github and started messing around with it on my own machine, I want to commit the changes I have made back to my fork on github but without commiting the changes I have made to the .cfg file, since this contains things like db password etc

推荐答案

使用这个:

Use this:

git update-index --skip-worktree path/file.cfg

还原:

And to restore:

git update-index --no-skip-worktree path/file.cfg

最后,如果您想列出标有 skip-worktree

Lastly, if you want to list files that are marked with skip-worktree:

git ls-files -v | grep ^S | awk '{print $2}'

为了简化,您可以在 $ HOME / .gitconfig

[alias]
    ls-ignored-changes = !git ls-files -v | grep ^S | awk '{print $2}'

然后你可以输入 git ls-忽略-更改。它甚至适用于自动完成,如果你有 git -completion (bash,tcsh,zsh)。

Then you can type just git ls-ignored-changes. It even works with auto-completion if you have the git-completion in place (for bash, tcsh, zsh).

这篇关于如何让git忽略所有进一步编辑为单个文件而不从存储库中删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆