如何从特定分支完全删除GitHub的最后两次提交

如何从特定分支完全删除GitHub的最后两次提交,git,github,Git,Github,在作为重复问题结束之前,请考虑我试图遵循的一些建议 我有两个分公司,我根本不想创建一个新的分公司:在我的公司里掌握和发展。我不想恢复,因为它将尽我所知保留历史记录(git reset——soft mylast good commit)。我真的不想碰师父。假设我在development中的最后两次提交,我做了一些非常丑陋的事情,我想从github中完全删除它们 我的最后一次提交:50021514(我想从github中删除,包括历史记录) 我的第二次最后提交:0b63ca64(我想从github中删

在作为重复问题结束之前,请考虑我试图遵循的一些建议

我有两个分公司,我根本不想创建一个新的分公司:在我的公司里掌握和发展。我不想恢复,因为它将尽我所知保留历史记录(git reset——soft mylast good commit)。我真的不想碰师父。假设我在development中的最后两次提交,我做了一些非常丑陋的事情,我想从github中完全删除它们

我的最后一次提交:50021514(我想从github中删除,包括历史记录)

我的第二次最后提交:0b63ca64(我想从github中删除,包括 (历史)

我的第三个承诺:571ebdfa(我希望从现在起这将成为头条)

可能性:

(一)

C:\dev\my app>git-rebase-p--571ebdfa

导致

pick 0b63ca6 bower dependency versions reseted  to fd042953
pick 4cce2c4 revert "bower dependency versions reseted"

# Rebase 571ebdf..4cce2c4 onto 571ebdf (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
然后我输入:wq,我得到了

interactive rebase in progress; onto 571ebdf
Last command done (1 command done):
   pick 0b63ca6 bower dependency versions reseted  to fd042953
Next command to do (1 remaining command):
   pick 4cce2c4 revert "bower dependency versions reseted"
You are currently rebasing branch 'MyBranch' on '571ebdf'.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

If you wish to skip this commit, use:

    git reset

Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.
Could not apply 0b63ca6... bower dependency versions reseted  to fd042953
但我仍然在github中看到所有alst两次提交。我是否在这里遗漏了一些额外的步骤,或者我是否错误地理解了可以使用“rebase-p ON”来达到我想要的结果

2) git rebase-i 571ebdfa

pick 0b63ca6 bower dependency versions reseted  to fd042953
pick 4cce2c4 revert "bower dependency versions reseted"

# Rebase 571ebdf..4cce2c4 onto 571ebdf (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
/c/dev/my-app/.git/rebase-merge/git-rebase-todo [unix] (10:23 14/06/2018)                    1,1 Top"C:/dev/my-app/.git/rebase-merge/git-rebase-todo" [unix] 21L, 755C
然后我试着:wq

我得到

Last command done (1 command done):
   pick 0b63ca6 bower dependency versions reseted  to fd042953
Next command to do (1 remaining command):
   pick 4cce2c4 revert "bower dependency versions reseted"
You are currently rebasing branch 'MyBranch' on '571ebdf'.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

If you wish to skip this commit, use:

    git reset

Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.
Could not apply 0b63ca6... bower dependency versions reseted  to fd042953
在这种情况下,当我们不仅要在本地存储库中而且还要在远程存储库中返回到上一次提交时,是否可以使用rebase

3) git revert 0b63ca64 50021514

This reverts commit 0b63ca6484cc9225c75b19ede27fe90e39e6d094.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch MyBranch
# Your branch is up to date with 'origin/MyBranch'.
#
# Last command done (1 command done):
#    pick 0b63ca6 bower dependency versions reseted  to fd042953
# Next command to do (1 remaining command):
#    pick 4cce2c4 revert "bower dependency versions reseted"
# You are currently rebasing branch 'MyBranch' on '571ebdf'.
#
/c/dev/my-app/.git/COMMIT_EDITMSG [unix] (10:34 14/06/2018)                                  1,1 Top"C:/dev/my-app/.git/COMMIT_EDITMSG" [unix] 20L, 738C
然后我输入:wq

我得到

[MyBranch 9276513] Revert "bower dependency versions reseted"
 2 files changed, 2 insertions(+), 1 deletion(-)
error: commit 50021514f6484eecff50e088686ed6b2f2203d47 is a merge but no -m option was given.
fatal: revert failed
从用户的角度来看,我只想删除特定分支中的最后两个提交以及它们的历史记录

这样做

git checkout develop

git checkout -b temp_branch

git reset --hard 571ebdfa #sha code from the commit where you want the head to point

git log #you should see all clean 

now do a force push to origin

git push -f origin develop
检查github中的日志

请记住,您刚刚推动了临时分支机构的发展,现在您还需要设置本地/发展

如果一切看起来都很好,那就做吧

git branch -D develop

git fetch 

git checkout develop

git branch -D temp_branch
这样做

git checkout develop

git checkout -b temp_branch

git reset --hard 571ebdfa #sha code from the commit where you want the head to point

git log #you should see all clean 

now do a force push to origin

git push -f origin develop
检查github中的日志

请记住,您刚刚推动了临时分支机构的发展,现在您还需要设置本地/发展

如果一切看起来都很好,那就做吧

git branch -D develop

git fetch 

git checkout develop

git branch -D temp_branch
我的最后一次提交:
50021514
(我想从github中删除,包括历史记录)

我的第二次最后提交:
0b63ca64
(我想从github中删除,包括历史记录)

我的第三次提交:
571ebdfa
(我希望从现在起这是我的头)

把这个放在透视图上,你想要这个:

---571ebdfa--0b63ca64--50021514
                           ^
                        develop
成为:

---571ebdfa
       ^
    develop
您使用的是
git-rebase--on
,这是正确的,您只是缺少了第二个参数:

git checkout develop
git rebase --onto 571ebdfa 0b63ca64
你可以这样想:

git rebase --onto <new-base> <old-base>
此时,您必须使用以下命令将重写的
develope
分支强制推送到上游存储库:

git push -f origin develop
或者只是:

git push -f
如果您的本地
develope
分支机构是远程
origin/develope
分支机构(很可能是这种情况)

我的最后一次提交:
50021514
(我想从github中删除,包括历史记录)

我的第二次最后提交:
0b63ca64
(我想从github中删除,包括历史记录)

我的第三次提交:
571ebdfa
(我希望从现在起这是我的头)

把这个放在透视图上,你想要这个:

---571ebdfa--0b63ca64--50021514
                           ^
                        develop
成为:

---571ebdfa
       ^
    develop
您使用的是
git-rebase--on
,这是正确的,您只是缺少了第二个参数:

git checkout develop
git rebase --onto 571ebdfa 0b63ca64
你可以这样想:

git rebase --onto <new-base> <old-base>
此时,您必须使用以下命令将重写的
develope
分支强制推送到上游存储库:

git push -f origin develop
或者只是:

git push -f

如果您的本地
develope
分支是远程
origin/develope
分支(很可能是这种情况)。

提交是历史记录…?我推送到github的最后三个提交是:50021514(今天)、0b63ca64(昨天)和571ebdfa(昨天之前)。今天和昨天,我推动了非常丑陋的变化。现在我希望我在github的分支与昨天完全一样,这样就看不到今天和昨天的历史了。@rkta我完全不同意我的问题是一样的。您可能没有阅读我尝试的内容和得到的结果。提交是历史…?我最后三次推送到github的提交是:50021514(今天)、0b63ca64(昨天)和571ebdfa(昨天之前)。今天和昨天,我推动了非常丑陋的变化。现在我希望我在github的分支与昨天完全一样,这样就看不到今天和昨天的历史了。@rkta我完全不同意我的问题是一样的。你可能没有读到我的尝试和结果。所以,唯一的方法是首先在本地复制我的分支,在本地重置复制的分支,然后用复制的重置分支完全覆盖原始分支?为了保证我们在同一页,我在问题中提到:我根本不想创建新的分支。好吧,如果没有别的捷径,那对我来说没关系。如果可能的话,我希望能以某种方式直接删除一系列的佣金。吉姆,你可以在同一个分支中这样做,我只是希望你更安全,我要求你创建一个新分支。只需执行git reset--hard 571ebdfa
git push-f origin develope
那么,唯一的方法就是首先在本地复制我的分支,在本地重置复制的分支,然后用复制的重置分支完全覆盖原始分支?为了保证我们在同一页,我在问题中提到:我根本不想创建新的分支。好吧,如果没有别的捷径,那对我来说没关系。如果可能的话,我希望能以某种方式直接删除一系列的佣金。吉姆,你可以在同一个分支中这样做,我只是希望你更安全,我要求你创建一个新分支。只需执行git重置--hard 571ebdfa
git push-f origin develop
我的问题已经被这两个问题很好地回答了。如果可能的话,请给出简短的评论,为什么我在571ebdfa 0b63ca64上执行git rebase时会得到“似乎已经有一个rebase合并目录…rm-fr”C:/dev/ing app sf bmid/.git/rebase merge”?为什么我可以“git”