簡體   English   中英

將壓扁的子樹更改推送到 gerrit

[英]Pushing Squashed subtree change to gerrit

添加子樹時:

git subtree add --prefix=vendor https://example.com/repo master --squash

創建了兩個提交。 一個用於壓扁的子樹提交

壓扁了 15fc2b6..c6dc29b 中的“供應商”更改

和合並提交

將提交 'SHA1' 合並到 master

當我想將此更改推送到 gerrit 時,它需要一個 changeID。 但是 git 不允許我做

git rebase -i HEAD~2

並像我對任何其他提交一樣進行返工,因為它是一個壓縮提交。

由於這個原因,現在我無法將此更改推送到 gerrit。 我無法直接將更改提交到 head (git) 並破壞超級模塊上的內容。 它必須經過構建和測試。 任何建議或幫助表示贊賞。

git filter-branch可以做很多事情,同時更新提交指針,使提交圖保持完整。 其中之一是運行命令來編輯所有提交消息,例如 Gerrit 的 commit-msg 鈎子。

git filter-branch HEAD...HEAD~1抓取git filter-branch HEAD...HEAD~1所有提交,但不抓取 HEAD~1,這對於 git-subtree 合並只是合並和壓縮提交。

git filter-branch --msg-filter接受一個命令來運行,該命令將提交消息通過管道輸入到標准輸入中,並將一個新的信息寫入標准輸出。 commit-msg 鈎子腳本在文件上工作,因此需要一些 shell 腳本來將原始消息寫入文件,運行鈎子,然后將文件 cat 到 stdout。

在推送到 Gerrit 之前,我已經把這一切都放在一個腳本中運行:

# 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}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM