How to tell git to ignore all further edit to a single file without removing it from the repo

断了今生、忘了曾经 提交于 2019-11-28 14:41:46

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/4114163/how-to-tell-git-to-ignore-all-further-edit-to-a-single-file-without-removing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!