缘起

之前与同事交流 git 时,简单介绍了 git shelltortoisegit (戏称 小乌龟tortoisesvn 操作极其相似)。

tortoisegit 的命令基本上与 git bash 中的命令一一对应。在 git bash 中提交变更到本地仓库需要先 git add 添加到暂存区,再通过 git commit 命令提交到仓库,但是在 tortoisegit 中可以使用 commit 命令 ”直接“ 提交到仓库。到底会不会经过暂存区呢? 我的理解是:会先添加到暂存区,然后再提交到仓库。到底是不是这样的呢?还是通过实验来观察。

小知识

默认,tortoisegit 会尽量使用 libgit2 来实现一系列的 git 操作。但是 libgit2 还有一些功能没实现,我想这就是为什么我们在安装 tortoisegit 的时候,会要求我们指定 git bash 的路径。

 

在 tortoisegit 执行 commit 会跳过暂存区直接提交到仓库中吗?
tortoisegit 配置

 

如果我们不希望使用 libgit2 而是完全使用 git.exe 来实现底层操作,我们可以在 tortoisegit 中禁用 UseLibgit2

 

在 tortoisegit 执行 commit 会跳过暂存区直接提交到仓库中吗?
禁用 UseLibgit2

 

关于 tortoisegit 的各项设置请参考 tortoisegit 官方手册

验证

做好设置后,我们可以开始验证了。

使用 process monitor 追踪 tortoisegit 的整个提交过程。查看执行了哪些 git 命令。

具体过程请参考下面的屏幕录像。

在 tortoisegit 执行 commit 会跳过暂存区直接提交到仓库中吗?

 

关键调用截图如下:

 

在 tortoisegit 执行 commit 会跳过暂存区直接提交到仓库中吗?
git-commit-command-details

 

我们主要关注的是如下两条命令:

git.exe update-index -- "a"

git.exe commit -F "C:\Users\BCN\AppData\Local\Temp\TortoiseGit\Pat2E66.tmp"

其中,git update-index -- "a"git add -- "a" 效果一样,都是把 文件 a 添加到暂存区。

git commit -F 表示提交,而且从文件中提取提交信息。

看来 ,在 tortoisegit 中提交的时候,也需要经过暂存区。

为什么每个指令都执行了两遍呢?我猜是因为 C:\Program Files\Git\bin\git.exe 不做实际工作。把工作都转交给相应的进程。我机器上是 C:\Program Files\Git\mingw64\bin\git.exe

参考资料

https://git-scm.com/docs/git-update-index

https://stackoverflow.com/questions/38585812/what-is-the-difference-between-git-add-and-git-update-index

相关文章:

  • 2021-04-05
  • 2022-12-23
  • 2022-02-08
  • 2021-05-26
  • 2021-06-10
  • 2021-11-01
  • 2021-04-28
  • 2021-07-04
猜你喜欢
  • 2022-02-26
  • 2021-06-27
  • 2022-01-07
  • 2021-10-06
  • 2021-07-26
相关资源
相似解决方案