如何修复 Git 中的上层提交?
How to fixup commits to upper in Git?
在 Git 中进行变基时,我们通常可以将多个提交合并(修复、压缩)到底部一个,例如 A, B, C -> A'
(此处 B 和 C 比 A 更新)。这不是一个好的做法,因为您看到 日期 开始工作(提交 A),但不是完成(提交 C)。就像你在 2019 年 9 月 23 日做了一个专题,但不是在 25.09 日做的。
现在我们有几个提交,想要将 A、B、C 修复到 C:A, B, C, D, E -> C', D', E'
。如何做到这一点?
我会这样做
# We first point to C
git checkout C
# Then we "unpack" changes between A and C into the working tree
git reset --soft A
# Let's now create commit C'
git commit -m "Message for C' (so A,B and C)"
# and finally we just have to bring back copies of D and E
git cherry-pick D E
在 Git 中进行变基时,我们通常可以将多个提交合并(修复、压缩)到底部一个,例如 A, B, C -> A'
(此处 B 和 C 比 A 更新)。这不是一个好的做法,因为您看到 日期 开始工作(提交 A),但不是完成(提交 C)。就像你在 2019 年 9 月 23 日做了一个专题,但不是在 25.09 日做的。
现在我们有几个提交,想要将 A、B、C 修复到 C:A, B, C, D, E -> C', D', E'
。如何做到这一点?
我会这样做
# We first point to C
git checkout C
# Then we "unpack" changes between A and C into the working tree
git reset --soft A
# Let's now create commit C'
git commit -m "Message for C' (so A,B and C)"
# and finally we just have to bring back copies of D and E
git cherry-pick D E