我正在开发一个项目(主项目),该项目有大约 100 次提交,没有分支等。
我想看看该项目在提交 1、然后在提交 10、20、30 时是什么样子。
如何查看早期提交而不丢失任何数据?
在我从之前的提交中看到它之后,我想回到现在的位置。
怎么做?我认为恢复更持久,我应该寻找其他东西吗?
只是为了看看(按照你的要求“看”)
git checkout [the name of the sha]
Run Code Online (Sandbox Code Playgroud)
你从做事中得到煞
git log
Run Code Online (Sandbox Code Playgroud)
在这里,您可以看到我检查了具有数百次提交的存储库的初始提交:
$ git checkout 772df05 # Enough of the sha to be unique, often 6-8 chrs.
Note: checking out '772df05'.
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 772df05... Initial commit
Run Code Online (Sandbox Code Playgroud)
查看文件,然后...
$ git checkout master
Run Code Online (Sandbox Code Playgroud)
最后一点 - 在切换分支之前,您可能需要注意两件事:
首先,应该添加或隐藏 git 中已存在的任何本地更改的文件(而不是新文件)。在学习 git 时,Added 可能是最简单的。
其次,任何已git add编辑的新文件或更改的文件都应该提交 - 即使只是作为“wip”。