我理解,对于许多情况来说,这是一个坏主意。我正在学习Git和实验。在这个练习中,没有代码会受到损害。
我创造了这样一个结构:
* [cf0149e] (HEAD, branch_2) more editing
* [8fcc106] some edit
|
| * [59e643e] (branch_2b) branch 2b
| /
|/
| * [0f4c880] (branch_2_a) branch 2a
| /
|/
* [a74eb2a] checkout 1
* [9a8dd6a] added branch_2 line
|
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
现在我想通过这个图表 重命名各种承诺 这样它们才有意义
例如:
* | [a74eb2a] checkout 1
* | [9a8dd6a] added branch_2 line
renamed to:
* | [a74eb2a] branch 2 commit 2
* | [9a8dd6a] branch 2 commit 1
注意:
[cf0149e] (HEAD, branch_2) more editing
[59e643e] (branch_2b) branch 2b
[0f4c880] (branch_2_a) branch 2a
所有分支都来自:
[a74eb2a] checkout 1
我尝试过
git rebase -i 328454f
然后将“选择”改为“编辑” 承诺,我想修改,然后运行
git commit --amend -m "the new message"
随着重设基准进程的继续。
这种方法的问题是,在上次 < code> git rebase -- continue 之后,我在我碰巧所在的分支上做了两个新的承诺(我要重命名的两个的复制件)。例如,在HEAD在“ branch_2” 时我运行了重新基准时,图表可能看起来是这样的:
* [cf0149e] (HEAD, branch_2) more editing
* [8fcc106] some edit
* [3ff23f0] branch 2 commit 2
* [2f287a1] branch 2 commit 1
|
| * [59e643e] (branch_2b) branch 2b
| /
| /
| | * [0f4c880] (branch_2_a) branch 2a
| | /
| |/
| * [a74eb2a] checkout 1
| * [9a8dd6a] added branch_2 line
|/
|
| * [bb903de] (branch_3) branch 3
|/
|
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
换句话说,我现在有两套承诺 代表完全相同的代码状态。
我只想改变承诺信息
我还要将初始信息从“ 测试” 重新命名为“ 初始版本 ” 。 我似乎无法使用 < code> git committee -- amend - m " 初始版本" code > 来进行它, 因为如果我检查了该承诺, 我最终会以无头模式结束 。
我做错什么了?
EDIT:
Here s an approach I just tried that works.
Of course, it re-writes history. So, outside of very special cases it is a bad idea.
Here are the steps:
Checkout the branch to be modified. Create patch files:
git format-patch HEAD~x // Where x is how far back from HEAD you need to patch
Edit the patch files to change the commit message. Now reset the head.
git reset --hard HEAD~x // Same x as before
应用补丁 :
git am 000*
New commits will be created with new SHA1 s.
If any branches now need to reference the new commits with the corrected messages you have to use git rebase
to move them over.
以我个人为例,在应用补丁程序后,
* [7761415] (HEAD, branch_2) branch 2 commit 4
* [286e1b5] branch 2 commit 3
* [53d638c] branch 2 commit 2
* [52f82f7] branch 2 commit 1
| * [bb903de] (branch_3) branch 3
|/
| * [59e643e] (branch_2b) branch 2b
| | * [0f4c880] (branch_2_a) branch 2a
| |/
| * [a74eb2a] checkout 1
| * [9a8dd6a] added branch_2 line
|/
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
So, I have my branch_2 commits nicely labeled.
Now I want to move branch_2a so that it branches out of [53d638c] branch 2 commit 2
取出分行_ 2a
git checkout branch_2a
重设它
git rebase 53d638c
现在我已经:
* [fb4d1c5] (HEAD, branch_2a) branch 2a
| * [7761415] (branch_2) branch 2 commit 4
| * [286e1b5] branch 2 commit 3
|/
* [53d638c] branch 2 commit 2
* [52f82f7] branch 2 commit 1
| * [bb903de] (branch_3) branch 3
|/
| * [59e643e] (branch_2b) branch 2b
| * [a74eb2a] checkout 1
| * [9a8dd6a] added branch_2 line
|/
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
与分支_2b相同的程序导致:
* [ca9ff6c] (HEAD, branch_2b) branch 2b
| * [fb4d1c5] (branch_2a) branch 2a
|/
| * [7761415] (branch_2) branch 2 commit 4
| * [286e1b5] branch 2 commit 3
|/
* [53d638c] branch 2 commit 2
* [52f82f7] branch 2 commit 1
| * [bb903de] (branch_3) branch 3
|/
| * [674e08c] (branch_1) commit 1
| * [7d3db01] added branch_1 line
|/
* [328454f] (0.0.0) test
Which is exactly what I was looking for. Not too messy. Again, not something you d want to do outside of very special cases. In my case I am just playing to learn Git, so the above isn t really affecting a real code repository. It s nice to know that you can do this if you have to.
现在开始重命名第一个承诺 。