首页 > 解决方案 > GIT 使用文件修改数据而不是文件内容

问题描述

我很好奇 git 是否可以检查实际文件而不是文件修改日期/时间。Git 目前只检查文件修改时间,即使文件内容相同,它也会显示为已修改。我们可以改变这种行为吗?

标签: git

解决方案


git当然不会这样。它检查文件修改日期,如果没有更改,则git决定文件没有被修改。但是,如果修改日期改变git 并不能决定文件是否被修改——它会检查内容。看:

$ git init test-git
Initialized empty Git repository in tmp/test-git/.git/

$ cd test-git/

$ echo >test.txt

$ git add test.txt 

$ git commit -m "Initial commit"
[master (root-commit) c02d9aa] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

$ git status
On branch master
nothing to commit, working tree clean

$ touch test.txt 

$ git status
On branch master
nothing to commit, working tree clean

touch更改文件时间戳但git仍认为文件未更改,因为它检查了内容并发现它相同。


推荐阅读