[英]Move branch commits to current one as uncommitted changes to working directory?
Lets say that I work on branchA
, and need to temporary commit all the uncommitted changes. 可以说我在branchA
工作,并且需要临时提交所有未提交的更改。 So I create branchB
, and commit everything. 所以我创建branchB
,并提交所有内容。
After some time, I need to move all those changes back to branchA
as uncommitted changes. 一段时间后,我需要将所有这些更改作为未提交的更改移回到branchA
。
(Some changes where to files that where not previously tracked in repo) (某些更改到以前在回购中未跟踪的文件的位置)
How can I do it? 我该怎么做? Merge + reset? 合并+重置? Is there simple command for it? 有简单的命令吗?
I could also rephrase this question as: 我也可以将此问题改写为:
How to undo git branch -b branchB; 如何撤消git branch -b branchB; git add .; git add。; git commit; git提交; ? ?
Assuming you are going to throw branchB
away, I would suggest doing git merge branchB --squash --no-commit
. 假设您要扔掉branchB
,我建议做git merge branchB --squash --no-commit
。 The --no-commit
option makes sure the changes are just applied to your working directory, as opposed to committed. --no-commit
选项可确保所做的更改仅适用于您的工作目录,而不是已提交。 The --squash
option prevents the commit that you eventually do from being a merge commit. --squash
选项可防止您最终所做的提交成为合并提交。 The reason I suggest using that option is that it is not a good idea to do anything besides the merge itself in a merge commit, and it seems like you want to do some more work locally before doing a "real" commit. 我建议使用该选项的原因是,除了在合并提交中执行合并本身之外,不执行任何其他操作是一个好主意,并且似乎您想在执行“实际”提交之前在本地进行更多工作。 Plus, this prevents your temp commit on branchB
from showing up in your history. 另外,这可以防止您在branchB
上的临时提交显示在您的历史记录中。
If you aren't dealing with a large number of files, just check out the individual files from the other branch: 如果您不处理大量文件,只需从另一个分支检出单个文件:
git checkout branchB <filename1>
git checkout branchB <filename2>
This brings in the files as they are at the head of the other branch. 这样就将文件带入另一个分支的开头。
You could go for cherry-pick --no-commit
: 您可以cherry-pick --no-commit
:
git checkout branchA
git cherry-pick branchB --no-commit
In the above I assume all is in a single commit, but you can extend that to a sequence of cherry-picks. 在上文中,我假设所有操作都在单个提交中,但是您可以将其扩展为一系列的樱桃小贴士。
See the cherry-pick reference for more info 有关更多信息,请参见“ 摘书”参考 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.