`checkout` =`reset` +`symbolic ref`? [英] `checkout` = `reset` + `symbolic ref`?

查看:83
本文介绍了`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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆