如何告诉 git 忽略对单个文件的所有进一步编辑而不将其从存储库中删除

发布于 2024-10-01 03:01:16 字数 101 浏览 0 评论 0原文

我在 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚然 2024-10-08 03:01:16

使用这个:

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

并恢复:

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

最后,如果您想列出标有 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-ignored-changes。如果您有 git-completion就位(对于 bash、tcsh、zsh)。

Use this:

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

And to restore:

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

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

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

To simplify, you can make an alias for that in your $HOME/.gitconfig:

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文