`checkout` =`reset` +`symbolic ref`? [英] `checkout` = `reset` + `symbolic ref`?
问题描述
假设a_branch
是一个现有分支,指向的提交与HEAD
所指向的提交不同(HEAD
可能直接或通过某些branch
指向一个提交).
Suppose a_branch
is an existing branch that points to a different commit than the one HEAD
points to (HEAD
might point to a commit directly or via some branch
).
以下命令是否等效?
git checkout a_branch
和
git symbolic-ref HEAD ref/heads/a_branch
git reset --hard a_branch
git symbolic-ref HEAD ref/heads/a_branch
git reset --hard a_branch
另请参见此相关帖子.
推荐答案
不,如果您在运行命令之前已进行了阶段性的更改或肮脏的更改,则不是.
No, they're not, if you have staged or dirty changes before you run the commands.
如果在运行git checkout
之前修改了先前存在的文件,则在移动HEAD
之后修改将继续存在.无论更改是分阶段进行还是变脏,都是如此.
If you modify a pre-existing file before running git checkout
, the modification will persist after HEAD
is moved. This is true whether the changes are staged or dirty.
在运行git reset --hard
时,该设置不成立.运行git reset --hard
时,已分阶段执行或已修改的修改将被销毁.
The same does not hold when running git reset --hard
. The modifications, staged or dirty, will be destroyed when you run git reset --hard
.
这篇关于`checkout` =`reset` +`symbolic ref`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!