Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 撤消尚未';我还没被推_Git_Undo_Git Merge - Fatal编程技术网

Git 撤消尚未';我还没被推

Git 撤消尚未';我还没被推,git,undo,git-merge,Git,Undo,Git Merge,在我的主分支中,我在本地执行了一个git合并其他分支,但从未将更改推送到originmaster。我不想合并,所以我想撤销它。在合并后执行git status时,我收到以下消息: # On branch master # Your branch is ahead of 'origin/master' by 4 commits. 根据一些情况,我试着跑步 git revert HEAD -m 1 但是现在我得到了一条带有git状态的消息: # On branch master # Your b

在我的主分支中,我在本地执行了一个git合并其他分支,但从未将更改推送到originmaster。我不想合并,所以我想撤销它。在合并后执行
git status
时,我收到以下消息:

# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
根据一些情况,我试着跑步

git revert HEAD -m 1
但是现在我得到了一条带有git状态的消息:

# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.

我不希望我的分支机构以任何数量的承诺领先。如何回到这一点?

您应该重置为上一次提交。这应该起作用:

git reset --hard HEAD^
或者甚至
HEAD^^
来恢复该恢复提交。如果您不确定应该后退多少步,您可以始终提供完整的SHA参考


如果出现问题且主分支没有任何本地更改,则可以重置为
origin/master

您应该重置为上一次提交。这应该起作用:

git reset --hard HEAD^
或者甚至
HEAD^^
来恢复该恢复提交。如果您不确定应该后退多少步,您可以始终提供完整的SHA参考


如果您遇到问题,并且您的主分支没有任何本地更改,您可以使用
git reflog
重置为
origin/master

,检查合并之前的提交(
git reflog
将是比
git log
更好的选择)。然后,您可以使用以下方法重置它:

git reset --hard commit_sha
还有另一种方法:

git reset --hard HEAD~1
它会让你回来的

请注意,任何已修改和未提交/未刷新的文件都将重置为其未修改状态。若要保留更改,请隐藏更改或查看下面的
--merge
选项


正如@Velmont在其回答中所建议的,在本直接案例中,使用:

git reset --hard ORIG_HEAD
可能会产生更好的结果,因为它会保留您的更改
ORIG_HEAD
将在合并发生之前直接指向提交,因此您不必自己寻找它


另一个技巧是使用
--merge
开关而不是
--hard
,因为它不会不必要地重置文件:

git reset --merge ORIG_HEAD
--合并

重置索引并更新工作树中与HEAD不同的文件,但保留索引与工作树之间不同的文件(即具有未添加的更改)


使用
git reflog
检查合并之前的提交(
git reflog
将是比
git log
更好的选择)。然后,您可以使用以下方法重置它:

git reset --hard commit_sha
还有另一种方法:

git reset --hard HEAD~1
它会让你回来的

请注意,任何已修改和未提交/未刷新的文件都将重置为其未修改状态。若要保留更改,请隐藏更改或查看下面的
--merge
选项


正如@Velmont在其回答中所建议的,在本直接案例中,使用:

git reset --hard ORIG_HEAD
可能会产生更好的结果,因为它会保留您的更改
ORIG_HEAD
将在合并发生之前直接指向提交,因此您不必自己寻找它


另一个技巧是使用
--merge
开关而不是
--hard
,因为它不会不必要地重置文件:

git reset --merge ORIG_HEAD
--合并

重置索引并更新工作树中与HEAD不同的文件,但保留索引与工作树之间不同的文件(即具有未添加的更改)


好吧,这里的其他人给我的答案很接近,但没有用。这就是我所做的

这样做

git reset --hard HEAD^
git status
…给了我以下状态

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.
然后,我不得不多次输入相同的
git reset
命令。每次我这么做,消息都会改变一个,正如你在下面看到的

> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.
在这一点上,我看到状态消息发生了变化,所以我尝试了一个
git pull
,这似乎很有效:

> git pull
Updating 2df6af4..12bbd2f
Fast forward
 app/views/truncated |    9 ++++++---
 app/views/truncated |   13 +++++++++++++
 app/views/truncated |    2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)
> git status
# On branch master
长话短说,我的命令归结为:

git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git pull

好吧,这里的其他人给我的答案很接近,但没有用。这就是我所做的

这样做

git reset --hard HEAD^
git status
…给了我以下状态

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.
然后,我不得不多次输入相同的
git reset
命令。每次我这么做,消息都会改变一个,正如你在下面看到的

> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 3 different commit(s) each, respectively.
> git reset --hard HEAD^
HEAD is now at [...truncated...]
> git status
# On branch master
# Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.
在这一点上,我看到状态消息发生了变化,所以我尝试了一个
git pull
,这似乎很有效:

> git pull
Updating 2df6af4..12bbd2f
Fast forward
 app/views/truncated |    9 ++++++---
 app/views/truncated |   13 +++++++++++++
 app/views/truncated |    2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)
> git status
# On branch master
长话短说,我的命令归结为:

git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git reset --hard HEAD^
git pull

我想你可以做
git-rebase-I[hash][branch\u name]
其中
[hash]
是你想倒回多远的地方加上一个(或者你想倒回多少个提交)的识别哈希,然后在编辑器中删除你不想再重复的提交行。保存文件。出口祈祷吧。它应该被重绕。您可能需要执行一个git重置--hard
,但在这一点上应该很好。如果您不想将特定提交保存在历史记录中,也可以使用它从堆栈中拉出,但这样会使存储库处于您可能不希望的状态。

我认为您可以执行
git rebase-I[hash][branch_name]
where
[hash]
是一个识别哈希值,表示您要倒回多远加上一次(或您要返回多少次提交),然后在编辑器中删除您不需要的提交行。保存文件。出口祈祷吧。它应该被重绕。您可能需要执行一个git重置--hard,但在这一点上应该很好。如果您不想将特定提交保留在历史记录中,但这可能会使存储库处于您可能不希望的状态,您也可以使用此功能从堆栈中提取特定提交。

假设您的本地主服务器不在源服务器/主服务器之前,您应该可以这样做

git reset --hard origin/master
然后您的本地
master
分支应该与
origin/master
相同

git merge --abort
$ git reflog
$ git reset --hard HEAD@{0}
fbb0c0f HEAD@{0}: commit (merge): Merge branch 'master' into my-branch
43b6032 HEAD@{1}: checkout: moving from master to my-branch
e3753a7 HEAD@{2}: rebase finished: returning to refs/heads/master
e3753a7 HEAD@{3}: pull --rebase: checkout e3753a71d92b032034dcb299d2df2edc09b5830e
b41ea52 HEAD@{4}: reset: moving to HEAD^
8400a0f HEAD@{5}: rebase: aborting
git merge --abort
git reset --merge
git reset --hard
git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.
git log --oneline feature-1
a1b2c3d4 Merge branch 'dev' into 'feature-1' <-- the merge you want to undo
e5f6g7h8 Fix NPE in the Zero Point Module <-- the one before the merge, you probably want this one
git checkout e5f6g7h8
git checkout -b feature-1
git reset HEAD~1
# Make sure what you are reverting is in fact the merge files
git add .
git reset --hard
git reset --hard remotes/origin/HEAD
git merge --abort
git merge --abort
git reset --hard origin/develop
git checkout master 
##to delete one branch, you need to be on another branch, otherwise you will fall with the branch :) 

git branch -D develop
git checkout -b develop origin/develop
git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back
# Checkout a given commit. 
# Doing so will result in a `detached HEAD` which mean that the `HEAD`
# is not pointing to the latest so you will need to checkout branch
# in order to be able to update the code.
git checkout <commit-id>

# create a new branch forked to the given commit
git checkout -b <branch name>
git reflog
git checkout HEAD@{...}
$ git log --graph --oneline --all
$ git merge feature-1
$ git log --graph --oneline --all
$ git reset --hard HEAD~1
$ git log --graph --oneline --all
git reset --merge ORIG_HEAD