2

有没有办法回滚到 git 中签入的内容的更早版本(对于整个 repo)?我不想更改 repo 中的内容,我只想要 9 个月前 repo 所在位置的本地副本。

4

2 回答 2

2

是的,只需克隆回购...

git clone <repo-url>

...从 9 个月前找到您想要的提交、分支或标签...

git log
git branch
git tag

...然后检查旧版本...

git checkout <commit-sha1, branch, tag>

请记住,如果您签出提交,您将处于分离的 HEAD 模式。如果您希望进一步提交,可以为该提交创建一个分支。

于 2013-01-08T00:09:06.250 回答
2

你可以直接告诉 git 从 9 个月前检出一个分支。这是我的一个项目中的一个示例:

:; git checkout 'master@{9 months ago}'
Checking out files: 100% (625/625), done.
Note: checking out 'master@{9 months ago}'.

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 b50869f... ignore DerivedData

指定修订的所有方法都记录在手册git-rev-parse中。

于 2013-01-08T00:15:57.053 回答