简体   繁体   English

Git不应该签入子模块是否已修改文件

[英]Git Should Not Checkin If Submodule Has Modified Files

Is there a built-in way (or a simple script) that won't let me check in if any of the submodules have modified files? 是否有内置方式(或简单脚本)不允许我检查任何子模块是否已修改文件? As it stands now, I have useless commits, since I cannot return to the submodule's state. 就目前情况而言,由于无法返回子模块的状态,因此我没有进行任何提交。

That looks like the pre-commit hook " script for submodule hygiene " is for: 看起来预提交的钩子“ 子模块卫生脚本 ”适用于:
preventing the commit if a submodule has pending changes. 如果子模块有待更改,则阻止提交。
(See also that patch/script ) (另请参阅该补丁/脚本

That script was written 4 years ago, so maybe the git diff now includes a simpler way of detecting "dirty" submodules. 该脚本是4年前编写的,因此git diff现在可能包含了一种检测“脏”子模块的更简单方法。

Thanks to VonC for explaining what I needed to do. 感谢VonC解释我需要做的事情。 Sorry I don't know Bash, so here's the Ruby version. 抱歉,我不了解Bash,所以这是Ruby版本。 Works perfectly (in all cases so far, tested with git version 1.7.9.4): 完美运行(到目前为止,在所有情况下,均已使用git版本1.7.9.4测试):

#!/usr/bin/env ruby
# http://stackoverflow.com/questions/12648585/git-should-not-checkin-if-submodule-has-modified-files
# October 1, 2012
# call this file pre-commit, make it executable and put it in .git/hooks
puts "Git pre-commit hook by Dan Rosenstark (yar)"
gitDiff = `git diff`
gitDiffWithSubmodules = `git diff --ignore-submodules`
if (gitDiff.length == gitDiffWithSubmodules.length)
  puts "Submodules are clean, going right ahead!"
else
  puts "One or more submodules are dirty, can't commit.'"
  exit 1
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM