您可能正在寻找git filter-branch
. 假设您的日志如下所示:
* commit 7534b4609b84b87232ad933c83d5b802adfe2814 (HEAD -> wip/T1234)
|
| More work on ticket #1234
|
* commit e23ef0941b7a52dbb46876db4c985a1c30ec5e16
|
| Some work on ticket #1234
|
* commit b660a05e4d90fc8ae61b7d39e716ee3cdcc382ec (develop)
|
| Current develop branch head
|
* commit 1b67c0b8b1b4f4c22ddc38ba78c499dde749006f
Initial commit
develop
因此,您拥有从到的提交的直线历史wip/T1234
。你意识到票应该是#1236,所以你运行:
$ git filter-branch --msg-filter 'sed -e s/1234/1236/g' \
> develop..wip/T1234
Rewrite 7534b4609b84b87232ad933c83d5b802adfe2814 (2/2) (0 seconds passed,
remaining 0 predicted)
Ref 'refs/heads/wip/T1234' was rewritten
$
现在提交被重写:
* commit c30e8becea1221d563d2be0e5a8c048c2c5bf608 (HEAD -> wip/T1234)
|
| More work on ticket #1236
|
* commit 0417b49944b3c9311031a657bc8be3c8bf05b54d
|
| Some work on ticket #1236
|
* commit b660a05e4d90fc8ae61b7d39e716ee3cdcc382ec (develop)
|
| Current develop branch head
|
* commit 1b67c0b8b1b4f4c22ddc38ba78c499dde749006f
Initial commit
原始 refs 的副本将被写入refs/original
,因此您仍然可以访问预过滤的版本:
$ git log refs/original/logs/refs/heads/wip/T1234
... version with #1234 still in place
显然,您要在删除原件之前仔细检查重写!