Git还原了

时间:2012-02-16 20:17:19

标签: git

git log

commit 2bf345e15dadba9f2e01ef2e0c3890d6cbab1153
Merge: d3b6ba8 aa94bf7
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Tue Feb 14 01:00:48 2012 -0500

    Merge branch 'master' of bitbucket.org:hobbes3/scoutmob

commit d3b6ba8f1d57c530c2d8ab9bb879fcac67d3de35
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Tue Feb 14 00:59:37 2012 -0500

    Revert "Added image info window"

    This reverts commit fad04be93334647d1b1e3b4d454a70819213ecac.

commit d119c3961da515c0cb2c6c9154003e52846cf848
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Tue Feb 14 00:22:56 2012 -0500

    Revert "Moved some files around to combine the common folder between scoutmob and ajax-example"

    This reverts commit 845f8d52c3655f3cf6b03da057281e5fb303721c.

commit aa94bf75fb064c6fe521501765d86c894aa5b436
Author: Another user <user_two@stackoverflow.com>
Date:   Sat Feb 11 10:42:03 2012 -0500

    removing .txt

commit b633d23a5b10ad7531855905d6f41897ce6726ad
Author: Another user <user_two@stackoverflow.com>
Date:   Sat Feb 11 10:40:04 2012 -0500

    testing data import

commit fad04be93334647d1b1e3b4d454a70819213ecac
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Sat Feb 11 03:55:54 2012 -0500

    Added image info window

commit 51f9cc7cd19f15540ac2631168a0a91c03a30139
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Tue Feb 7 22:29:58 2012 -0500

    Added deal info to the info window of the marker.

....

commit 845f8d52c3655f3cf6b03da057281e5fb303721c
Author: Stack Overflow User <user@stackoverflow.com>
Date:   Tue Jan 31 10:42:21 2012 -0500

    Moved some files around to combine the common folder between scoutmob and ajax-example

&#39; git status&#39;说

# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#
nothing to commit (working directory clean)

git branch -rv

origin/HEAD    -> origin/master
origin/master  aa94bf7 removing .txt
origin/working cb65aef My location now works. Will work on the graphics next.

几天前,我的主分支处于fad04be的最新提交。然后我决定暂时查看我的旧代码。所以我使用git revert 845f8d5恢复了回来。

事后来看,我意识到我应该先检查一个新分支。然后我尝试使用git revert 'fad04be返回。当我运行git status时,它会说Your branch is ahead of 'origin/master' by 1 commit.

接下来我尝试从远程存储库中git pull来恢复我当前的代码,现在我感到很困惑。

我只希望我的本地和远程存储库都在提交fad04be。我做错了什么,我该怎么办?

3 个答案:

答案 0 :(得分:4)

注意:在您遵循我的任何建议之前,请复制您的目录。这样你就可以随时回到目前的情况

正如ouah所提到的那样,你的主人现在应该正是你想要的,有两个额外的提交,即845f8d5和fad04be的恢复。

你现在可以做两件事。如果你还没有向遥控器推送任何东西,你可以通过

将主指针放回fad04be
git reset --HARD fad04be

或者,如果您已将某些东西推到遥控器或其他人身上,则可以恢复还原。如果你做一个git日志,你会看到最近的两个提交是845f8d5和fad04be的恢复。您可以通过执行

来还原这些还原
git revert <commit-id-of-revert>

下次要查看旧版本时,确实使用:

git checkout <revision-id>

别忘了做

git checkout master

当你完成了。如果你改变并提交的东西没有这样做,你的提交将去某个地方而不是在主分支(git会抱怨处于一个独立的头状态,但这个警告很容易错过 - 相信我,我一直在那里:))

太看旧版本,不需要先创建另一个分支。

答案 1 :(得分:1)

git revert实际上是一个只撤消先前提交的提交。我拿它拉什么都没做?你应该只需要推动还原。

答案 2 :(得分:1)

使用git checkout <commit-id>快速查看提交。 git revert <commit-id>将通过添加新提交来还原单个提交<commit-id>