回到 SourceTree 中的上一个提交
Going back to previous commit in SourceTree
我是 Git 的新手,我正试图恢复到之前在 SourceTree 中的提交。我右键单击要还原到的提交,然后单击结帐。它给了我一个提示,说我的工作副本将成为一个独立的头。这是什么意思,这是我应该避免的事情吗?
这个问题似乎与 git 并不完全相关,而是特定于您正在使用的 git 客户端/提供商(我怀疑是 bitbucket)。
我建议您使用命令行客户端,而不是 Web UI 以更好地学习 git。
在分离头状态下,您所做的任何更改(和提交)都会从提交树中分离出来,您需要额外的工作才能将该提交放回提交树。通常我们不会对 detached head 状态进行更改,它用于重新安排提交树。但值得在分离状态下进行试验。
根据 Git-Tower 的文章:What's a "detached HEAD" in Git?
Understanding how "checkout" works
With the "git checkout" command, you determine which revision of your
project you want to work on. Git then places all of that revision's
files in your working copy folder.
Normally, you use a branch name to communicate with "git checkout"
$ git checkout development
However, you can also provide the SHA1 hash of a specific commit
instead:
$ git checkout 56a4e5c08
Note: checking out '56a4e5c08'.
You are in 'detached HEAD' state...
This exact state - when a specific commit is checked out instead of a
branch - is what's called a detached HEAD.
The problem with a detached HEAD
The HEAD pointer in Git determines your current working revision (and
thereby the files that are placed in your project's working
directory). Normally, when checking out a proper branch name, Git
automatically moves the HEAD pointer along when you create a new
commit. You are automatically on the newest commit of the chosen
branch.
When you instead choose to check out a commit hash, Git won't do this
for you. The consequence is that when you make changes and commit
them, these changes do NOT belong to any branch. This means they can
easily get lost once you check out a different revision or branch: not
being recorded in the context of a branch, you lack the possibility to
access that state easily (unless you have a brilliant memory and can
remember the commit hash of that new commit...).
总结:
从 SourceTree,请签出到特定分支,而不是签出到特定提交。
2020 年 12 月 9 日。
我正在使用 Sourcetree。如果你想去你以前的提交,你可以双击以前的提交。之后,如果你愿意,你可以创建一个新分支并与你的旧分支合并。
我是 Git 的新手,我正试图恢复到之前在 SourceTree 中的提交。我右键单击要还原到的提交,然后单击结帐。它给了我一个提示,说我的工作副本将成为一个独立的头。这是什么意思,这是我应该避免的事情吗?
这个问题似乎与 git 并不完全相关,而是特定于您正在使用的 git 客户端/提供商(我怀疑是 bitbucket)。
我建议您使用命令行客户端,而不是 Web UI 以更好地学习 git。
在分离头状态下,您所做的任何更改(和提交)都会从提交树中分离出来,您需要额外的工作才能将该提交放回提交树。通常我们不会对 detached head 状态进行更改,它用于重新安排提交树。但值得在分离状态下进行试验。
根据 Git-Tower 的文章:What's a "detached HEAD" in Git?
Understanding how "checkout" works
With the "git checkout" command, you determine which revision of your project you want to work on. Git then places all of that revision's files in your working copy folder.
Normally, you use a branch name to communicate with "git checkout"
$ git checkout development
However, you can also provide the SHA1 hash of a specific commit instead:
$ git checkout 56a4e5c08 Note: checking out '56a4e5c08'. You are in 'detached HEAD' state...
This exact state - when a specific commit is checked out instead of a branch - is what's called a detached HEAD.
The problem with a detached HEAD
The HEAD pointer in Git determines your current working revision (and thereby the files that are placed in your project's working directory). Normally, when checking out a proper branch name, Git automatically moves the HEAD pointer along when you create a new commit. You are automatically on the newest commit of the chosen branch.
When you instead choose to check out a commit hash, Git won't do this for you. The consequence is that when you make changes and commit them, these changes do NOT belong to any branch. This means they can easily get lost once you check out a different revision or branch: not being recorded in the context of a branch, you lack the possibility to access that state easily (unless you have a brilliant memory and can remember the commit hash of that new commit...).
总结: 从 SourceTree,请签出到特定分支,而不是签出到特定提交。
2020 年 12 月 9 日。
我正在使用 Sourcetree。如果你想去你以前的提交,你可以双击以前的提交。之后,如果你愿意,你可以创建一个新分支并与你的旧分支合并。