简体   繁体   English

Git 替换本地分支并将我的分支重新设置在新分支之上

[英]Git replace the local branch and rebase my branch on top of the new one

I am pretty sure the answer to this question may be found on SO, at least in bits and pieces on several different posts.我很确定这个问题的答案可以在 SO 上找到,至少在几个不同的帖子上都是零零散散的。 I have a branch that was created of a different branch.我有一个由不同分支创建的分支。 I have made some commits in my branch and then the owner of the other branch has force pushed some commits onto my branch.我在我的分支中做了一些提交,然后另一个分支的所有者强制将一些提交推送到我的分支上。 After that happened, I have made a few more commits.在那之后,我又做了一些提交。

Now I am asked to get his clean version (by which I think he meant to replace my local branch) and then rebase my branch on top of the new branch (his?) so that his commits (the "force-pushed" ones) will go away.现在我被要求获取他的干净版本(我认为他的意思是替换我的本地分支),然后将我的分支重新设置在新分支(他的?)之上,以便他的提交(“强制推送”的)将 go 带走。 By that I think what he wants is to never see his commits in the history of my branch.我认为他想要的是永远不会在我的分支历史中看到他的提交。

What would be the steps to do this?执行此操作的步骤是什么? I found a lot of references to我找到了很多参考资料

git fetch
git reset --hard @{u}
git rebase -i origin/master

but not sure of the outcome as I don't seem to be able to get rid of his commits.但不确定结果,因为我似乎无法摆脱他的承诺。 For anyone needing a visual picture of what I am talking about, here it is:对于任何需要我正在谈论的内容的视觉图片的人,这里是:

在此处输入图像描述

Any suggestions would be greatly appreciated.任何建议将不胜感激。 I am using Git Bash, btw.我正在使用 Git Bash,顺便说一句。

TIA, Ed TIA,埃德

Edit: as requested, here is the output of the "git log --graph --oneline --all" command (Sorry, I had to cover all the comments as some may contain sensitive info):编辑:根据要求,这里是“git log --graph --oneline --all”命令的output(对不起,我必须涵盖所有评论,因为有些评论可能包含敏感信息):

在此处输入图像描述

One tip, post the output of git log --graph --oneline --all with your HEAD, so we have a better insight on what is going on.一个提示,将 output 的git log --graph --oneline --all与您的 HEAD 一起发布,以便我们更好地了解正在发生的事情。

If I understood correctly, you should try the following: (make sure you don't force push something. Use hash codes for arguments on reset )如果我理解正确,您应该尝试以下操作:(确保您不要强行推动某些东西。在reset时使用 arguments 的 hash 代码)

git reset his-last-commit (to uncommit recent edits after his commits) git reset his-last-commit (在他提交后取消提交最近的编辑)

git stash (to save them) git stash (保存)

git reset --hard your-commit (this deletes his commits) git reset --hard your-commit (这会删除他的提交)

git stash pop (this applies your recent edits on top) git stash pop (这将您最近的编辑应用在顶部)

If this doesn't work, you should try git cherry-pick如果这不起作用,您应该尝试git cherry-pick

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

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