【问题标题】:git pre-commit hook: changed files are not in the current commitgit pre-commit 钩子:更改的文件不在当前提交中
【发布时间】:2015-07-21 23:35:28
【问题描述】:

我有一个 git pre-commit 钩子,如果它们损坏,它会更改一些文件。钩子完成后,更改的文件不会在当前提交中列出。如何将钩子中的更改暂存到当前提交中?

我的钩子是这样的:

#!/bin/sh
versionUpdater -editVersion

这会打开一个 Windows 窗体,我可以在其中编辑某些文件的某些版本。完成编辑后,我希望这些更改在当前提交中。

挂钩中的这些更改现在列在下一次提交中。

【问题讨论】:

  • 请在此处发布您的代码 :)

标签: git pre-commit-hook


【解决方案1】:

有多种选择。 以下答案将详细解释需要做什么以及如何做。

Can a Git hook automatically add files to the commit?.

在预提交中:

  • 触摸一个文件 .processCommit 什么的。 (请务必将此添加到 .gitignore)
#!/bin/sh 
echo 
touch .processCommit 
exit

在提交后:

如果 .processCommit 存在,您就知道提交刚刚发生。

#!/bin/sh
echo
if [ -a .commit ]
    then
    rm .commit
    git add yourfile
    git commit --amend -C HEAD --no-verify
fi
exit

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 2014-02-15
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多