英文:
How can I push changes to a remote branch on GitHub without having to create a rebase node on git tree?
问题
我最近刚从Gerrit迁移到GitHub,目前正在寻找适合的工作流程。我目前的工作流程如下:
开始
--- a (主分支, 远程主分支)
创建分支并进行更改
--- a (主分支, 远程主分支) --- b (新分支)
git add .
git commit
git push --set-upstream origin 新分支
--- a (主分支, 远程主分支) --- b (新分支, 远程新分支)
如果 (新分支正常) =>
将远程新分支合并到远程主分支并删除远程新分支
git branch -D 新分支
git remote prune origin # 清理已合并的远程分支,因为某种原因它们仍然出现在本地
git checkout 主分支 && git pull
--- a --- b (主分支, 远程主分支)
如果 (新分支不正常) =>
编辑新分支
git add .
git commit --amend
--- a (主分支, 远程主分支) --- b (远程新分支)
\
--- c (新分支)
在这里,由于某种原因,我无法只使用 git push --set-upstream origin 新分支
推送更改到上游,所以我必须执行 git pull --rebase
。
在这一步,我必须进行大量的变基,即使它们只是可以轻松合并为无效的更改,例如:只需在空行上添加 return;
就会导致如下变化:
<<<<<<< HEAD
=======
return;
>>>>>>> [demo_bazel] 添加虚拟测试
在大量变基后:
--- a (主分支, 远程主分支) --- b (远程新分支) --- c (新分支)
然后我最终可以再次执行 git push --set-upstream origin 新分支
--- a (主分支, 远程主分支) --- b --- c (新分支, 远程新分支)
我的目标是,如果可能的话,如何让我在新分支上进行的所有更改都保持在同一个节点上? 这意味着最后一行将没有 b:
--- a (主分支, 远程主分支) --- c (新分支, 远程新分支)
原因在于,我不希望所有无用的 b 节点使我的git树变得臃肿,在Gerrit中,它们过去会通过执行 git push ${1-origin} HEAD:refs/for/master%r=reviewer
来保持整洁,无需任何麻烦地位于主分支节点上创建 git commit --amend
。我已经在上述描述了我目前的工作状态,因为这是问题的一部分。
英文:
I have just recently moved from Gerrit to GitHub and am currently figuring out a fitting workflow. My workflow at the present is as following:
start
--- a (master, origin/master)
Create branch and make changes
--- a (master, origin/master) --- b (new_branch)
git add .
git commit
git push --set-upstream origin new_branch
--- a (master, origin/master) --- b (new_branch, origin/new_branch)
if ( new_branch is fine ) =>
merge origin/new_branch to origin/master and delete origin/new_branch
git branch -D new_branch
git remote prune origin #clean merged origin branches as for some reason it still appear at local
git checkout master && git pull
--- a --- b (master, origin/master)
if (new_branch is NOT fine) =>
edit new_branch
git add .
git commit --amend
--- a (master, origin/master) --- b (origin/new_branch)
\
--- c (new_branch)
at here, for some reason I can't just git push --set-upstream origin new_branch
to push the change upstream
so I have to do a git pull --rebase
at this step, I have to do an excessive rebase which marks ALL of my new changes as conflicts even when they could just merge to nothingness, for example: just add a return; onto a blank line would make
it become
<<<<<<< HEAD
=======
return;
>>>>>>> [demo_bazel] add dummy test
after the excessive rebase:
--- a (master, origin/master) --- b (origin/new_branch) --- c (new_branch)
only then I can finally do git push --set-upstream origin new_branch
again
--- a (master, origin/master) --- b --- c (new_branch, origin/new_branch)
My goal is, if possible, how can I make all of the changes I make on new_branch stays on only 1 node, always? that means the last line would be without the b in between:
--- a (master, origin/master) --- c (new_branch, origin/new_branch)
the reason here is that I wouldn't want all the useless b nodes to bloat my git tree, in Gerrit they used to stay neatly and effortlessly in 1 git node above the master node by doing git push ${1-origin} HEAD:refs/for/master%r=reviewer
after creating a git commit --amend
.
I have described all of my currently working status on the above as it's a part of the question
答案1
得分: 0
我已找到上述问题的解决方案。
对于第一次提交后的以下编辑,只需使用以下命令将新更改推送到远程分支:
git push --force-with-lease
英文:
I've found the solution for the problem above
for the following edits after the first commit, just use the below to push new changes to the remote branch:
git push --force-with-lease
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论