Git:为什么在结账到旧分支后,新的提交消失了?

时间:2013-10-21 13:38:03

标签: git

我对文件进行了一些更改并提交了它们。然后我结账到一个较旧的分支。

之后我发现我所做的所有更改都消失了,我所做的提交也消失了。

如何找到我所做的所有更改?


修改

这是从我的终端历史记录中复制的:

$ git commit -m 'done clean FNAG Yishu'
[detached HEAD 8a67a04] done clean FNAG Yishu
 3 files changed, 1121 insertions(+)
 create mode 100644 data/data_afterClean/amazon_Revised.txt
 create mode 100644 data/data_afterClean/epinions_Revised.txt
 create mode 100644 data/data_afterClean/slideshare_Revised.txt

但是当我尝试push时会发生错误:

$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

To https://github.com/xxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/xxx.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration variable
hint: to 'simple', 'current' or 'upstream' to push only the current branch.

2 个答案:

答案 0 :(得分:3)

你已经承诺了一个独立的头而不是一个分支。您可以使用git commit输出中列出的SHA-1返回提交:

git checkout 8a67a04

如果要将此提交保留在分支上,请在结帐后创建:

git checkout -b <branchname>

答案 1 :(得分:1)

提交被记录为您提交时所在分支的新提示,因此您可以通过签出该分支来切换回来。

日志始终显示您当前所在分支的历史记录;当checkout切换分支时,你不再在你提交的分支上,所以它不再显示。