让git永远不要推送单个提交? [英] Getting git to never push a single commit?
问题描述
我不认为这是可能的,但认为有人可能对如何实现这一点有一个漂亮的想法:
我有一个项目,我检查了早在我接手之前就已经存在了。我在各种文件中做了大约十次更改,我从不想检入(它们都是配置更改)。
有什么办法可以提交这组更改并且那么从来没有实际推动那个提交?我知道这听起来很奇怪)
澄清:
我希望这些更改留在我的工作目录中,我需要他们让应用程序在本地运行。我希望能够保持提交其他更改,甚至在同一个文件中的更改,但不要将配置更改推送到其他任何地方...
它有点像在每次推送之前,我都会想要:
这是一种类似的模式,可以将本地补丁集保存到您不控制的上游项目中。处理这个问题的最简单方法是创建一个中间分支,所有更改都会合并到一起,如下所示:
___________________________ master
\ __________________________ config-changes
\ _____________________日常工作
master
包含要共享的所有内容。在 config-changes
中提交的唯一内容是您希望在共享时轻松恢复的更改。 daily-work
是您完成所有工作的分支。要设置它,请执行:
#(此时没有本地配置更改应该在master中)
git checkout -b config-changes master
#使您不想要的与配置相关的更改共享
git commit -am进行本地配置更改
git checkout -b日常工作
#以普通的方式工作并提交
当您准备好分享您的更改时,请执行以下操作:
git rebase --onto master config-changes daily-work
git checkout master
git merge daily-work
这将恢复在 config-changes
中所做的所有更改,但否则会使其看起来像直接从主
。请注意,如果您想继续在 daily-work
中工作,则需要将其重新绑定到 config-changes
,但最好为每次更改创建一个新分支。
当您需要从 master
,do:
git checkout master
git pull
git checkout config-changes
git merge master
合并将您本地的配置更改重新应用到最新的主设备。然后,您可以自由创建一个新的 daily-work
分支,或者将 config-changes
合并到旧分支中,作为适当的。基本上,你绝不会直接从 master
合并到 daily-work
中。你总是先经过 config-changes
第一个。
起初它似乎有很多工作,但是一旦你做一次或两次,你会发现它比手动维护更改要容易得多。
I don't think this is possible, but thought someone might have a nifty idea of how to accomplish this:
I have a project that I checked out that was in existence long before I took it over. I have about a dozen changes in various files that I never want checked in (they're all config changes).
Is there any way to commit this set of changes and then never actually push that one commit? I know it sounds odd :)
clarification:
I want these changes to stay in my working directory, I need them for the app to function locally. I want to be able to keep commit other changes around them, even changes in the same file, but never push the config changes to anywhere else...
It's somewhat like before every push I would want to:
- cherry pick and stash this one commit
- rebase the one commit out
- push
- re-apply this stash to my codebase
This is a similar pattern to maintaining a local patch set to an upstream project you don't control. The easiest way to handle this is to have an intermediate branch that all changes get merged through, like this:
___________________________ master
\__________________________ config-changes
\_____________________ daily-work
master
contains everything that is to be shared. The only things committed in config-changes
are changes you want to be able to revert easily when they are shared. daily-work
is the branch you do all your work in. To set it up, do:
# (no local config changes should be in master at this point)
git checkout -b config-changes master
# Make your config-related changes that you don't want to share
git commit -am "Made local config changes"
git checkout -b daily-work
# Work and commit like normal
When you're ready to share your changes, do:
git rebase --onto master config-changes daily-work
git checkout master
git merge daily-work
That will revert all the changes made in config-changes
, but otherwise make it look like you branched directly from master
. Note that after you do this rebase, if you want to continue to work in daily-work
, you need to rebase it back onto config-changes
, but it's really better to create a new branch for each change.
When you need to pull down new changes from master
, do:
git checkout master
git pull
git checkout config-changes
git merge master
The merge reapplies your local config changes onto the latest master. You're then free to create a new daily-work
branch, or merge config-changes
into the old one, as appropriate. Basically, you never merge directly from master
into daily-work
. You always go through config-changes
first.
It seems like a lot of work at first, but once you do it once or twice you'll see it's a lot easier than maintaining the changes manually.
这篇关于让git永远不要推送单个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!