简体   繁体   English

Git 将更改从一个分支复制到另一个分支,而不提交源分支中的更改

[英]Git copy changes from one branch to another without committing the changes in source branch

I am new to git.我是 git 的新手。 I have a branch named BranchA from the master.我有一个来自 master 的名为 BranchA 的分支。 I have some changes in BranchA (I am not going to merge changes from BranchA to master).我在 BranchA 中进行了一些更改(我不会将 BranchA 中的更改合并到 master 中)。 Now I have created another branch from the master named BranchB.现在我从名为 BranchB 的 master 创建了另一个分支。 I want the changes from BranchA to BranchB.我想要从 BranchA 到 BranchB 的更改。 Here, I don't want to commit the changes in BranchA.在这里,我不想提交 BranchA 中的更改。 And changes in the BranchA(which are copied to BranchB) should get deleted. BranchA 中的更改(复制到 BranchB)应该被删除。

Make sure the changes you have is uncommited and unstaged.确保您所做的更改未提交且未暂存。 Then you can use git stash:然后你可以使用 git 存储:

git stash

Then move to your Branch B and then:然后移动到您的分支 B,然后:

git stash apply

If you want to include the new changes from BranchA to BranchB then first commit and push on Branch A but if you don't want to commit the changes then first discard the current changes.如果您想包含从 BranchA 到 BranchB 的新更改,则首先提交并推送分支 A,但如果您不想提交更改,则首先丢弃当前更改。 Then switch to new branch usind git checkout BranchB then try pulling branch git pull origin BranchA然后使用git checkout BranchB切换到新分支,然后尝试拉分支git pull origin BranchA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM