我在一个Branch上工作,例如Branch1,我在本地进行了更改,然后提交了更改,但是当我尝试推送更改时,它失败了,因为该分支现在受到了保护(当我开始使用它时不是这样) ,所以现在我想将所有这些更改移动/提交到新分支并提高PR。
我从Branch1创建了一个分支Branch2,并结帐到branch2。
但是我看不到我在Branch1中进行/提交的任何更改。
除了重做所有工作外,我有什么办法可以将所有更改提交到branch2。
答案 0 :(得分:1)
无需创建新分支。
在Branch1
中,您可以指定使用git push时要推送到哪个分支:
git push remote Branch1:remotebranch
答案 1 :(得分:0)
说您已经完成:
git checkout develop
git checkout -b branch1
ed README.txt
git commit -am 'edit README'
git push
,最后一次“推送”失败。您可以使用与branch2
相同的内容和历史来创建新分支branch1
:
git checkout branch1 # already here from the previous block
git checkout -b branch2 # create the new branch
git log develop..branch2 # shows the commit from above
git push
清理陈旧的分支也很有帮助;根据您是否希望branch1
存在,以下两种方法都可以起作用:
# Delete the unmerged branch1 with the wrong content
git branch -D branch1
# Reset branch1 to match the upstream
git checkout branch1
git fetch
git reset --hard origin/branch1