我试图以git认为其分离的方式结帐到git分支的最新提交。我无法结帐到分支机构本身,因为git worktree阻止了这种互动,并使用$ mkdir temp1
$ cd temp1
$ git init
$ echo a > test.txt
$ git add test.txt
$ git commit -m "Initial commit"
$ git worktree add ../temp2 --no-checkout
$ cd ../temp2
$ git checkout master
fatal: 'master' is already checked out at '../temp1'
绕过了这一点。
git checkout 392847
在" temp2"存储库,我可以使用其哈希值git log
手动结帐到提交,我想在不键入git checkout origin/master
的情况下自动执行此操作,复制id,然后将其粘贴到git checkout命令行中。
我想要的示例:(类似于包含推送工作的存储库的$ git checkout <magic prefix> master
Note: checking out '<magic prefix>/master'.
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>
):
function('function_name', param1, param2)
答案 0 :(得分:1)
怎么样:
$ git checkout --detach master
这将有效地解析主分支的提交SHA1,然后将其作为分离的HEAD进行检查。执行相同操作的其他方法是git checkout $(git rev-parse master)
或更短的git checkout master^0
。
或者,您始终可以创建指向同一提交(git checkout -b master-copy master
)的新分支,或使用完整克隆(git clone temp1 temp2
)。
答案 1 :(得分:0)
最简单的方法是git checkout --detach master