用Git撤消临时更改 [英] Undoing temporary changes with Git

查看:106
本文介绍了用Git撤消临时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我在'master'并且有一个blob:

Say, I'm on 'master' and have a blob:

DEBUG = FALSE
CACHE_SIZE = 100
code
code
code

现在我开始调试一个新的分支...

Now I start debugging in a new branch...

DEBUG = TRUE # Don't forget to turn off!
CACHE_SIZE = 0 # Don't forget to set back to 100!

...修复一些错误,更改一些代码...并将我的修复程序并入master '。但不幸的是,我忘记将这些不要忘记-s返回到原始值。

... fix some bugs, change some code... and merge my fixes back into 'master'. But unfortunately I have forgotten to return these "don't forget"-s to the original value.

如何自动执行将一些行返回原来的过程值?或者至少将它缩短到单个命令。

How can I automate the process of returning some lines back to the original value? Or at least shorten it to a single command.

也许,一些临时提交或存档还是其他一些技巧?

Maybe, some temporary commit, or stash, or some other technique?

推荐答案

Cameron对于短期调试更改有一些很好的想法。我想添加一个常见的,即使对于更大或更多的永久性本地调试更改也是如此,就像您通常在每次添加功能时都做出相同的不要忘记更改。我听说它被称为织机,被子,堆叠的分支和管道。您可以找到具有这些名称的插件,以帮助维护这种工作流程,但是它们之间存在微妙的差异,我从来没有真正掌握过,而且手法并不难做到这一点。

Cameron has some good ideas for shorter term debug changes. I wanted to add a common one that works even for larger or more permanent sets of local debug changes, like if you commonly make the same "don't forget" changes every time you add a feature. I've heard it called a loom, quilt, stacked branches, and a pipeline. You can find plugins with those names to help maintain this kind of workflow, but there are subtle differences between them I've never really grasped, and the technique is not too difficult to do manually.

基本思想是您在 master 功能之间添加另一个分支,让我们称之为 debug 。您使所有的不要忘记该分支中的更改,然后从调试再次分支,使功能,其中包含您将以生产方式进行的所有更改正常。然后,要删除所有不要忘记功能中的更改,请执行以下操作:

The basic idea is you add another branch between master and feature, let's call it debug. You make all your "don't forget" changes in that branch, then branch off again from debug to make feature, which contains all your changes that will go into production as normal. Then, to remove all your "don't forget" changes in feature, do:

git rebase --onto master debug feature

这使它看起来像你从 master> / em>,并且从未在调试分支中添加更改。然后你就像普通的那样合并到 master 。下次要添加功能时,您只需将 master 合并到调试中,您的不要忘记更改将自动重新应用于最新的上游代码。然后,只需从调试创建一个新的功能分支,并重新开始循环。

That makes it look like you branched straight from master and never added the changes in the debug branch. Then you merge into master like normal. The next time you want to add a feature, you just merge master into debug and your "don't forget" changes are automatically reapplied to the latest upstream code. Then just create a new feature branch from debug and the cycle starts again.

显然,您还需要记住在合并之前进行rebase进入 master 。如果您忘记了卡梅伦的勾子,可以防止合并。

Obviously, you still have to remember to do the rebase before merging into master. Cameron's hook idea can be used to prevent merges if you forget.

这篇关于用Git撤消临时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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