2016-10-28 22 views
5

虽然增加一个子树:推压扁子树变化到格里特

git的子树添加前缀=厂商https://example.com/repo主 --squash

有创建了两个的提交。一个用于挤压树承诺

Squashed 'vendor' changes from 15fc2b6..c6dc29b 

和合并提交

Merge commit 'SHA1' into master 

当我想要把这个变化格里特,它需要一个changeID。但Git并不让我做一个

git rebase -i HEAD~2

和返工像我这样做对其他任何承诺,因为它是一个压扁的承诺。

现在我不能把这个改变推向gerrit,因为这个。我无法直接将更改提交到头部(git),也无法将超级模块上的东西破坏。它必须经过构建和测试。任何建议或帮助表示赞赏。

回答

0

git filter-branch可以做很多事情,同时更新提交指针,使提交图保持不变。其中之一就是运行一条命令来编辑所有的提交消息,比如Gerrit的commit-msg钩子。

git filter-branch HEAD...HEAD~1抓取HEAD中的所有提交,但不是HEAD〜1,这对于git-subtree合并只是合并和压缩提交。

git filter-branch --msg-filter需要一个命令来运行它获取提交消息在标准输入输入,并写入一个新的标准输出。 commit-msg钩子脚本在文件上工作,所以需要一些shell脚本将原始消息写入文件,运行钩子,然后将文件捕获到stdout。

我已经把所有的脚本推到格里特之前运行:

# This command re-writes the history after doing a git subtree {pull|add} 
# to add Gerrit Change-Id lines to the squash commit message. 
# 
# It assumes that HEAD is the merge commit merging the subtree into HEAD. 
# The original HEAD commit will be backed up under refs/original, which 
# is helpful if something goes wrong. 

set -e 
set -o pipefail 

GIT_DIR=$(readlink -f $(git rev-parse --git-dir)) 
TMP_MSG="${GIT_DIR}/COMMIT_MSG_REWRITE" 

git filter-branch --msg-filter \ 
    "cat > ${TMP_MSG} && \"${GIT_DIR}/hooks/commit-msg\" ${TMP_MSG} && \ 
    cat \"${TMP_MSG}\"" HEAD...HEAD~1 

rm -rf ${TMP_MSG}