[英]How to move the HEAD to the latest date in git?
What I wish to do is to get the version of the file that has a specific comment, get it and use it, then change it to the latest code. 我想要做的是获取具有特定注释的文件的版本,获取并使用它,然后将其更改为最新的代码。
git log -g --grep="code submitted version 0.1.2.3"
This returns a hash 123456
, then I do: 这返回一个哈希值
123456
,然后我这样做:
git checkout 123456
and use the older version. 并使用旧版本。
Now I want to change the HEAD
back to the latest. 现在我想将
HEAD
更改回最新版本。 This I could not do. 这是我做不到的。 I have tried:
我努力了:
git reset --hard
git clean -f
git pull
Any ideas? 有任何想法吗?
When you called git checkout 123456
you moved your HEAD
from the commit you were currently on (most likely the head of the master
branch) to the commit 123456
. 当您调用
git checkout 123456
您将HEAD
从您当前所在的提交(很可能是master
分支的负责人)移动到提交123456
。 Therefor you are looking for a way to move HEAD
back to the branch you were previously on, which you can do with: 因此,您正在寻找一种方法将
HEAD
移回您之前所在的分支,您可以使用以下方法:
git checkout master
If you want to take a look at a specific revision of a file, you can either just view it using 如果要查看文件的特定修订版,可以使用它来查看它
git show 123456:/txt/file.txt
or temporarily check out only this file with 或者暂时只用这个文件签出
git checkout 123456:/txt/file.txt
// use it
git checkout :/txt/file.txt
Explanation of your tries : 你尝试的解释 :
git reset --hard
Reverts all changes of the current HEAD
, but does not move HEAD
. 恢复当前
HEAD
所有更改,但不移动HEAD
。 After a reset, git status
shows that everything is "clean". 重置后,
git status
显示一切都“干净”。
git clean
Removes all untracked files from the working tree, again HEAD
is not moved. 从工作树中删除所有未跟踪的文件,再次移动
HEAD
。
git pull
Fetches the upstream changes and merges them in. Not what you want. 获取上游更改并将它们合并。不是您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.