简体   繁体   English

将分支提交到当前目录作为对工作目录的未提交更改?

[英]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.

相关问题 如何在Git上将未提交的更改从一个分支移动到另一个分支 - How to move changes as uncommitted from one branch to another on Git 将未提交的更改从当前分支移动到与那些更改冲突的另一个分支 - Move uncommitted changes from current branch to another branch that conflicts with those changes 从当前工作目录中未提交的更改创建一个 git 补丁 - Create a git patch from the uncommitted changes in the current working directory 使用git,如何将一些未提交的更改从一个分支移动到另一个文件夹中的另一个分支? - Using git, how do you move some uncommitted changes from one branch to another branch in a different folder? 将master分支中未提交的更改移至dev分支并还原master - Move uncommitted changes in master branch to dev branch and revert master 当前分支上有未提交的更改时签出另一个分支 - Checkout another branch when there are uncommitted changes on the current branch 咕噜; 警告:工作目录中未提交的更改 - Grunt; Warning: uncommitted changes in working directory Git(无分支)具有未提交的更改 - Git (no branch) with uncommitted changes Git:将当前的主节点变成分支并保留未提交的更改 - Git: Turn current master into branch and keep uncommitted changes 如果当前分支有未提交的更改,如何防止git合并 - How to prevent git merge if current branch has uncommitted changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM