Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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/4/regex/18.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_Git Checkout_Git Detached Head_Git Branch Sculpting - Fatal编程技术网

Git 在分离的头上按主控键提交

Git 在分离的头上按主控键提交,git,git-checkout,git-detached-head,git-branch-sculpting,Git,Git Checkout,Git Detached Head,Git Branch Sculpting,我想重做以前提交的更改 Maxims-MacBook-Air:hellodebug.com maximveksler$ git log commit 7f9dd753d39fd65b4272af713ef9c07a9f84f016 Author: Maxim Veksler <maxim@vekslers.org> Date: Sun Dec 28 09:12:17 2014 +0200 Imagine a Supercomputer Helping You Fix B

我想重做以前提交的更改

Maxims-MacBook-Air:hellodebug.com maximveksler$ git log
commit 7f9dd753d39fd65b4272af713ef9c07a9f84f016
Author: Maxim Veksler <maxim@vekslers.org>
Date:   Sun Dec 28 09:12:17 2014 +0200

    Imagine a Supercomputer Helping You Fix Bugs Faster

commit 54561ed320633e72bb35a7ab668a9996e6ffca8f
Author: Maxim Veksler <maxim@vekslers.org>
Date:   Sun Dec 28 08:57:25 2014 +0200

    highcharts tweaks

commit d57144cbd004b3b9e893e8d50d7077634824ce9a
Author: Genady Okrain <genady@okrain.com>
Date:   Mon Dec 22 18:46:21 2014 +0200

    sash api
到目前为止还不错,现在让我们来修复

Maxims-MacBook-Air:hellodebug.com maximveksler$ git commit -a -m'Back to not fucking it up'
[detached HEAD b5cb3e4] Back to not fucking it up
但现在我需要把这件事推回给大师,并提升团队。混乱的部分来了

Maxims-MacBook-Air:hellodebug.com maximveksler$ git checkout HEAD
Maxims-MacBook-Air:hellodebug.com maximveksler$ git status
HEAD detached from 54561ed
nothing to commit, working directory clean
Maxims-MacBook-Air:hellodebug.com maximveksler$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Maxims-MacBook-Air:hellodebug.com maximveksler$ git push origin HEAD:master
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
To git@github.com:maximveksler/hellodebug.com.git
 ! [rejected]        HEAD -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:maximveksler/hellodebug.com.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git up不会和我们说话,这很酷。我其实并不需要它

Maxims-MacBook-Air:hellodebug.com maximveksler$ git checkout master
Warning: you are leaving 2 commits behind, not connected to
any of your branches:

  e9e202c no border
  b5cb3e4 Back to not fucking it up

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch new_branch_name e9e202c

Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
什么?不回来吧,我爱你

Maxims-MacBook-Air:hellodebug.com maximveksler$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
迷路了!永远?我希望不是

Maxims-MacBook-Air:hellodebug.com maximveksler$ git reflog
7f9dd75 HEAD@{0}: checkout: moving from e9e202c4703939064e099b735ceeb6b78dc7933a to master
e9e202c HEAD@{1}: commit: no border
b5cb3e4 HEAD@{2}: commit: Back to not fucking it up
54561ed HEAD@{3}: checkout: moving from master to 54561ed320633e72bb35a7ab668a9996e6ffca8f
7f9dd75 HEAD@{4}: commit: Imagine a Supercomputer Helping You Fix Bugs Faster
54561ed HEAD@{5}: commit: highcharts tweaks
好吧,那么它们就在野外的某个地方,但是我怎么才能把它们弄回来呢?现在说再见还为时过早


帮助?

如果修复速度合理,我会再次修复,但方式不同,从您的错误提交开始

git reset --hard HEAD^ # brings your entire master branch and working copy back to where it worked
git reset origin/master # brings your HEAD pointer back to origin/master but leaves your working copy with the working code
# fix code
git commit -a -m'try to not fuck it up'
git push
另一种方法是恢复错误的提交,清楚地表明它是错误的,然后进行修复

git revert HEAD^
# fix code
git commit -a -m'better code this time'
git push # pushes two commits, the revert and the new code
如果你想把你已经得到的代码保存在一个分离的头上,你应该能够
cherry pick
在上面的两个流中,而不是修复代码,只需
git cherry pick b5cb3e4


祝你好运。

因为你已经推送了提交
7f9dd753d39fd65b4272af713ef9c07a9f84f016
我建议你执行
git还原

首先签出你的主人,然后做什么

git revert 7f9dd753d39fd65b4272af713ef9c07a9f84f016
这将在
master
上创建一个新的提交,该提交将还原
7f9dd753
中引入的更改

现在签出作为新分支所做的修复(您可以在reflog
e9e202c HEAD@{1}:commit:no border
中看到commit id)

master
上重新设置
myFix
更改的基础

git rebase master
git branch -D myFix
git push origin master
切换回
master
并将其快进到重新设置基址的
myFix
分支

git checkout master
git merge myFix
现在,您可以删除
myFix
分支并按下
master

git rebase master
git branch -D myFix
git push origin master

要将分离磁头上所做的更改推送到原点/主控点(或其他分支),请尝试:


如果您收到警告,请确保您的原始版本是最新的(您可以先尝试提取它)。虽然如果您正在修改提交或,并且您确信您的更改是最新的,但是您可以强制推送它(
-f
/
--force
)。不建议这样做,除非您知道自己在做什么(如重新定基)。

您可以将上游
主节点
分支与
-s ours
策略(或
-s theres
在主节点上时)合并。因此,您不会破坏历史记录(如
git reset--hard
或rebase操作),而是保持工作树


当单个
git revert
不能满足要求时(例如,当货物和上游分支之间存在合并时),此方法尤其有用.

@ta.speot.is将问题转移到工具上并不能代替理解实际发生的情况以及如何解决问题。@Abizern我建议他使用SourceTree查看分支。它与高度定制版本的
git log
没有太大区别
git branch -D myFix
git push origin master
git push origin HEAD:master