使用git reset –soft而不使用提交ID

huangapple go评论65阅读模式
英文:

Use of git reset --soft without the commit id

问题

git reset --soft 没有提及提交ID时是否有使用场景?我理解当与提交ID相关联时,它非常有用。

英文:

Is there any use case in using just git reset --soft without mentioning the commit id? I understand its great help when there's a commit id associated with it

答案1

得分: 1

不是真的。

如果没有提交 ID,该命令对你的分支或工作目录没有任何影响。
它会将当前分支重置到已经存在的提交,而不会更改任何文件。

但是,它会在 git reflog 中为当前的 Git 头部创建一个简单的条目,类似于这样:

15bf991eb HEAD@{0}: reset: moving to HEAD

然而,这也没有特别有用。
因为在 reflog 中已经有一个类似的头部条目;当你最后一次切换/重置/提交/合并/拉取/克隆时,它已经存在。

所以也许唯一的用例是教育目的,用于演示 git reset 如何创建 git reflog 条目(而实际上不需要更改任何内容)。

英文:

Not really.

Without commit-id that command does nothing to your branch or working directory.<br>
It resets the current branch to the commit it's already on, without changing any files.

However, it does create a simple entry for git's current head in the git reflog, which will look something like this:

15bf991eb HEAD@{0}: reset: moving to HEAD

That's not particularly useful either though.<br>
Because there already is a similar entry for that head in the reflog; from when you last switched/reset/committed/merged/pulled/cloned.

So maybe the only use-case is for educational purposes, for demonstrating how git reflog entries will be created by git reset (without actually needing to change anything).

huangapple
  • 本文由 发表于 2023年6月27日 21:18:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76565317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定