Git:防止登台一些文件,自动登台 [英] Git: prevent staging some files, automatically stage all
问题描述
我想暂停当前工作副本中的所有内容,但会自动将所有未来编辑的文件和hunk 分段。
例如,我正在使用与正在工作的项目上的大多数其他人不同版本的CocoaPods。我想升级配置文件的配置,以便与我的CocoaPods兼容而不会破坏它们。最简单的方法是不要将新配置包含在拉取请求中,但这意味着我无法构建。隐藏和弹出不起作用,因为如果在编辑配置后隐藏并应用我的更改,弹出将修复配置,但可以撤消更改。
我应该如何修复解决方案
但是对于该回购的其他用户而言,这种方式仍然是不可见的。
如果这些修改已被很好地定义(并且不是全部在 这样,一个 和 这样,配置文件出现永远不会改变为git。 I would like to unstage everything in my current working copy, but automatically stage all files and hunks I edit in the future. For example, I am using a different version of CocoaPods than most other people on the project I am working on. I would like to upgrade the configuration of the configuration files to be compatible with my CocoaPods without breaking theirs. The easiest way to do this is to not include the new configuration in a pull request, but that means I can't build. Stashing and popping won't work because if I stash after editing the configuration and then apply my changes, popping will fix the configuration but undo my changes. How should I fix this? One way would be to modify that configuration file in a way which is visible only by you locally. If those modifications are well defined (and not all over the place in add a smudge script associated to (edit or create a The The That way, a And the That way, the config file appears to never change as far as git is concerned. 这篇关于Git:防止登台一些文件,自动登台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! your.config.file
),那么你可以考虑
(图片来自自定义Git - Git属性,来自 Pro Git book )
$ $ $ $ $ $ $ $ $ $ $ $ g $ git config过滤器/ cd / path / to / your / local / cloned / repo。 filterconfig.smudge'update_config'
git config filter.filterconfig.clean'restore_config'
update_config
和 restore_config
脚本可以在本地 $ PATH
(它们在bash中,即使你在Windows上也是如此,因为它们将由mingw git bash执行)。
$ b update_config code>脚本会:
git pull
触发工作树的更新会自动重新生成配置文件的内容并进行本地修改。
restore_config
脚本会在文件被git调用时恢复文件的保存副本(它将由 git status
或 git触发例如:
cat saved_copy
But in a way that remains invisible for the other users of that repo.your.config.file
) then you could consider a content filter driver in order to generate the right content for that config file on checkout:
your.config.file
files in a .gitattributes
declaration:your.config.file filter=filterconfig
.gitattributes
file at the root folder of your local repo, and add the line above in it. You can add, commit and push that file: it won't have any impact for other users).
(image from "Customizing Git - Git Attributes", from "Pro Git book")cd /path/to/your/local/cloned/repo
git config filter.filterconfig.smudge 'update_config'
git config filter.filterconfig.clean 'restore_config'
update_config
and restore_config
scripts can anywhere on your local $PATH
(they are in bash, even if you are on Windows, since they will be executed by the mingw git bash).update_config
script would:
git pull
which triggers an update of the working tree would automatically re-generate the config file content with the local modifications needed.restore_config
script would restore the saved copy of the file whenever it is called by git (it would be triggered by a git status
or a git diff
for instance):cat saved_copy