git:将本地提交在一个分支中传播到另一个分支

时间:2019-03-29 18:32:15

标签: git

我不确定我的术语是否正确,但是我有一个git工作区,其中一次提交

(workspace1)$ git status
On branch mainline
Your branch is ahead of 'origin/mainline' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

(workspace1)$ git remote show origin
* remote origin
  Fetch URL: ssh://git.company.com:2222/pkg/ServiceA

我想将该分支(workspace1)中的提交提交到另一个工作空间(workspace2),该工作空间已同步到主线

(workspace2) $ git status
On branch mainline
Your branch is up to date with 'origin/mainline'.

nothing to commit, working tree clean

(workspace2)$ git remote show origin
* remote origin
  Fetch URL: ssh://git.company.com:2222/pkg/ServiceA

基本上,我想对我在工作区1(在另一个工作区)中所做的更改进行更改,但我不想在对工作区1的更改进行代码审查时被其阻止

im对git不太熟悉,但是我认为不受阻碍的另一种方法是继续在工作区1中进行更改,但是如果我需要在原始提交中处理一些代码注释,然后分支新更改,然后提交更改并重新应用我正在工作的分支?

1 个答案:

答案 0 :(得分:1)

一块蛋糕

// In workspace 1:
$ git checkout -b ealeon-branch  # Create a new branch for yourself.
$ git push -u origin eleaon-branch  # Push the branch to origin.

// In workspace 2:
$ git fetch  # Update remote info so it knows about your new branch.
$ git checkout eleaon-branch  # Checkout the branch you pushed.

您可以从eleaon分支打开PR,然后将其合并到任何位置。如果您在工作区1中进行了其他更改,则可以将其向上推,然后将其拉下(合并到其中)2。