我在gh-pages
分支机构,当我
$ git add <file>
$ git commit -m "<message>"
我看到了
# On branch gh-pages
nothing to commit, working directory clean
然后我会做,看看以下
$ git stage
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
$ git status
# On branch gh-pages
nothing to commit, working directory clean
我试图深入挖掘弄清楚什么搞砸了
$ git log
commit d7122828ef232829e28654f4bc56022829d03722
Author: siddhion <siddhion@gmail.com>
Date: Wed Jul 24 19:00:19 2013 +0200
1st push to gh-pages
$ git reflog
d712282 HEAD@{0}: checkout: moving from master to gh-pages
9bf529e HEAD@{1}: checkout: moving from gh-pages to master
d712282 HEAD@{2}: commit (initial): 1st push to gh-pages
我不确定这里发生了什么,但在此之前我试图摆脱我上次提交尝试以下命令
git reset --soft HEAD
git reset --hard HEAD
git reset HEAD
git reset .
git reset
也许我对那些事情做得更糟。不确定。我也试过
$ git push origin gh-pages
Counting objects: 1156, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (1141/1141), done.
Writing objects: 6% (70/1156), 2.27 MiB | 680.00 KiB/s
然后我立即取消因为我不想再提交/添加了。
如何恢复/删除最后一次提交/添加并重新开始干净?
好的,我第一次关注我是John Galt的回答。我跑了
$ git checkout d712282
并得到了这个
Note: checking out 'd712282'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at d712282... 1st push to gh-pages
此时我真的不知道该怎么办。我想要的只是回到我的gh-pages
分支,不再让那个大坝d712282
困扰我。所以那时我
$ git checkout gh-pages
愚蠢的是,我认为d712282
提交已经与独立的头部一起死亡,所以我在做之前就像我一样继续
git add index.html
但是当我检查是否上演时我得到了
$ git stage
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
在这一点上,似乎没有任何改变,但我继续只是为了彻底。当我尝试运行提交时,我得到了
$ git commit -m "added index.html to gh-pages"
# On branch gh-pages
nothing to commit, working directory clean
然后我做了
$ git status
# On branch gh-pages
nothing to commit, working directory clean
我希望看到正在运行的$ git log
给了我什么
$ git log
commit d7122828ef232829e28654f4bc56022829d03722
Author: siddhion <siddhion@gmail.com>
Date: Wed Jul 24 19:00:19 2013 +0200
1st push to gh-pages
有相同的旧d712282
提交。我也跑了$ git reflog
并得到了
$ git reflog
d712282 HEAD@{0}: checkout: moving from d7122828ef232829e28654f4bc56022829d03722
d712282 HEAD@{1}: checkout: moving from gh-pages to d712282
d712282 HEAD@{2}: checkout: moving from d7122828ef232829e28654f4bc56022829d03722
d712282 HEAD@{3}: checkout: moving from gh-pages to d712282
d712282 HEAD@{4}: checkout: moving from master to gh-pages
9bf529e HEAD@{5}: checkout: moving from gh-pages to master
d712282 HEAD@{6}: commit (initial): 1st push to gh-pages
这一点我尝试了Geoffrey的建议并且跑了并且得到了
$ git reset --hard d712282
HEAD is now at d712282 1st push to gh-pages
所以在这一点上我想要做的就是摆脱d712282,因为每次我尝试git push origin gh-pages
git开始推动d712282提交,它有1156个文件。方式太多了。我希望它死了。
答案 0 :(得分:0)
如果要还原提交,则需要重置为先前的提交ID,而不是HEAD
git reset --hard d712282
如果您没有修改任何内容,git add / commit将不执行任何操作。
答案 1 :(得分:0)
您需要从git log
开始,或者如果您需要更清晰的语法git log --oneline
,这将显示您的提交历史记录,以便您可以找到您要查找的提交历史记录。一旦你拥有了与你关心的提交一致的SHA-1(这就是为什么描述性提交消息是好的)。您可以显式签出该提交,如下所示
git checkout WHAT_EVER_THE_SHA-1_TAG_IS
这将使您的暂存索引设置为该提交,您可以继续工作。另请阅读有关日志的说明,以便了解如何让自己摆脱这些情况,并始终非常小心reset --hard
https://www.kernel.org/pub/software/scm/git/docs/git-log.html