如何从Git存储库中删除选定的提交日志条目,同时保持其更改? [英] How to remove selected commit log entries from a Git repository while keeping their changes?
问题描述
我想从线性提交树中删除选定的提交日志条目,以便条目不会显示在提交日志中。
I would like to remove selected commit log entries from a linear commit tree, so that the entries do not show in the commit log.
我的提交树看起来像例如:
My commit tree looks something like:
R--A--B--C--D--E--HEAD
我想删除B和C条目,以便它们不会显示在提交日志中,但会从A更改为D应该保留。也许通过引入单个提交,以便B和C成为BC并且树看起来像。
I would like to remove the B and C entries so that they do not show in the commit log, but changes from A to D should be preserved. Maybe by introducing a single commit, so that B and C become BC and the tree looks like.
R--A--BC--D--E--HEAD
理想情况下,A直接到达D后。 D'表示从A到B,B到C和C到D的变化。
Or, ideally, after A comes D directly. D' representing changes from A to B, B to C and C to D.
R--A--D'--E--HEAD
这可能吗?如果是的话,怎么样?
Is this possible? if yes, how?
这是一个相当新的项目,所以现在没有分支,因此也没有合并。
This is a fairly new project so has no branches as of now, hence no merges as well.
推荐答案
git-rebase(1) 的确如此。
$ git rebase -i HEAD~5
$ b $ git awsome-ness [git rebase --interactive] 包含一个示例。
git awsome-ness [git rebase --interactive] contains an example.
- 不要在public(远程)提交中使用
git-rebase
。
- Make确保您的工作目录是干净的(
commit
或stash
您当前的更改)。 - 运行上面的命令。它启动您的
$ EDITOR
。 - 在<$ c $之前替换
pick
c> C 和D
由压扁
。它将把C和D融入到B中。如果你想删除一个提交,那么就删除它的一行。
- Don't use
git-rebase
on public (remote) commits. - Make sure your working directory is clean (
commit
orstash
your current changes). - Run the above command. It launches your
$EDITOR
. - Replace
pick
beforeC
andD
bysquash
. It will meld C and D into B. If you want to delete a commit then just delete its line.
如果你迷路了,键入:
If you are lost, type:
$ git rebase --abort
这篇关于如何从Git存储库中删除选定的提交日志条目,同时保持其更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!