简体   繁体   English

还原合并的拉取请求

[英]Revert a merged pull request

I'm working on a project where we have different branches (dev, feature,production) .我正在开发一个我们有不同分支(开发、功能、生产)的项目 I was working on my feature branch, and did multiple commits on that branch for my changes.我正在我的feature分支上工作,并在该分支上为我的更改做了多次提交 Later at some point I took a pull from dev branch and that got merged with my feature branch (which I shouldn't have done).后来在某个时候,我从dev分支中提取了一个 pull 并与我的feature分支合并(我不应该这样做)。 But, I didn't realised that mistake at that time, and kept working on my feature branch, and did some more commits.但是,我当时没有意识到这个错误,并继续在我的feature分支上工作,并做了更多的提交。

Now I want to only revert that pull taken from dev and keep all my commits of feature branch, also the one I did after the pull.现在我只想恢复从dev获取的 pull 并保留我对feature分支的所有提交,也是我在 pull 之后所做的。 Is it possible to save those commits?是否可以保存这些提交? I know a little about Git Reset/revert command, but that will not save my later commits i guess.我对Git Reset/revert命令了解一点,但我猜这不会保存我以后的提交。 It will point HEAD to previous commit, before the pull.它将在拉取之前将HEAD指向先前的提交。

Can anyone help how I can save my commits made after that merge?任何人都可以帮助我如何保存合并后所做的提交? Or my understanding isn't correct regarding Reset\\Revert command?或者我对Reset\\Revert命令的理解不正确?

Note-: Changes are already committed and pushed on remote.I'm using Source Tree .注意-:更改已经提交并推送到远程。我正在使用Source Tree

  1. In Sourcetree, double click the last commit before the merge.在 Sourcetree 中,双击合并前的最后一次提交。 Doing so will make your working copy a 'detached HEAD' etc这样做会使您的工作副本成为“分离的 HEAD”等

  2. Click "New Branch" and give it a name.单击“新分支”并为其命名。

  3. Navigate to all the commits you did after the merge, right-click them and choose "Cherry Pick"导航到您在合并后所做的所有提交,右键单击它们并选择“Cherry Pick”

You just have to reset your checked out branch (with git reset --hard ) to the point you want it to be.您只需要将签出的分支(使用git reset --hardgit reset --hard到您想要的程度。 You may have to use git reflog if the point you desire has been lost.如果您想要的点丢失了,您可能必须使用git reflog

Until people don't realize, a bad usage of git can lead to developers losing their changes.直到人们没有意识到,对 git 的错误使用可能导致开发人员丢失他们的更改。 It is convenient to backup changes using local mirrors sometimes.有时使用本地镜像备份更改很方便。

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

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