本文介绍了从树中完全删除本地提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个本地unpushed提交,我想从树中删除提交#3,所以提交#4的父母将指向提交#2



我是这么做的?



描述我的意思的图片:

解决方案

您可以使用 git rebase -i

  git rebase -i HEAD〜5 

允许您以交互方式选择最后一个(在这种情况下为5 )提交你想使用,编辑,挤压,...



你将得到一个文件来编辑;像这样:

 选择a58f195提交1 
选择abe6821提交2
选择f74035d提交3
pick 3f171df commit 4
pick afa24a9 commit 5

其中您将删除该行指向你不想要的提交。注意,你可以使用交互式rebase做更多的事情:)

I have 5 local unpushed commits and I want to delete commit #3 from the tree, so parent of commit #4 would point to commit #2

How would I do that?

An image describing what I mean:

解决方案

you can use git rebase -i :

git rebase -i HEAD~5

allows you to interactively choose which of the last (5 in this case) commits you wish to use, edit, squash,...

You will get a file to edit; like this:

pick a58f195 commit 1
pick abe6821 commit 2
pick f74035d commit 3
pick 3f171df commit 4
pick afa24a9 commit 5

in which you will just delete the line pointing to the commit you don't want anymore.. Note that you can do much more with the interactive rebase :)

这篇关于从树中完全删除本地提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:25