jub*_*0bs 28 git sha git-amend
为什么即使我在运行后没有对提交(消息,文件)进行任何更改,我最新提交的SHA-1哈希值也会发生变化git commit --amend?
假设我在命令行运行以下命令.
cd ~/Desktop
mkdir test_amend
cd test_amend
git init
echo 'foo' > test.txt
git add test.txt
git commit -m 'initial commit'
Run Code Online (Sandbox Code Playgroud)
然后,调用
git log --pretty=oneline --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
打印以下消息:
b96a901 initial commit
Run Code Online (Sandbox Code Playgroud)
然后我做
git commit --amend
Run Code Online (Sandbox Code Playgroud)
但我改变主意,决定不改变最后一次提交中的任何内容.换句话说,我保持最后一次提交的文件,目录和消息不变(我只保存消息文件并关闭我的编辑器).
然后,我做
git log --pretty=oneline --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
再一次,我看到提交的哈希值发生了变化:
3ce92dc initial commit
Run Code Online (Sandbox Code Playgroud)
是什么导致哈希改变?是否与提交的时间戳有关?
Tho*_*mas 31
是的,这是提交时间戳.检查两个提交的内容揭示:
$ git cat-file commit 82c7363bcfd727fe2d6b0a98412f71a10c8849c9
tree d87cbcba0e2ede0752bdafc5938da35546803ba5
author Thomas <xxx> 1400700200 +0200
committer Thomas <xxx> 1400700200 +0200
hello
$ git cat-file commit 7432fcf82b65d9d757efd73ef7d6bff4707f99bd
tree d87cbcba0e2ede0752bdafc5938da35546803ba5
author Thomas <xxx> 1400700200 +0200
committer Thomas <xxx> 1400700214 +0200
hello
Run Code Online (Sandbox Code Playgroud)
如果你在原始提交的同一秒内修改,可能你会得到相同的哈希值.
修改 Git 提交会更改提交日期(与您最初运行时看到的日期不同git log- 运行git log --format=fuller以查看提交日期)。创建提交哈希时会考虑提交日期。
接下来的事情是创建commit sha对象
我试图弄清楚为什么在重置之后提交SHA ID是不同的,并且再次使用具有相同父级和树对象引用的相同用户添加具有完全相同提交消息的相同文件.
| 归档时间: |
|
| 查看次数: |
11081 次 |
| 最近记录: |