如何从Git存储库中删除选定的提交日志条目,同时保持其更改? [英] How to remove selected commit log entries from a Git repository while keeping their changes?

查看:98
本文介绍了如何从Git存储库中删除选定的提交日志条目,同时保持其更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从线性提交树中删除选定的提交日志条目,以便条目不会显示在提交日志中。

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.


  1. 不要在public(远程)提交中使用 git-rebase
  2. Make确保您的工作目录是干净的( commit stash 您当前的更改)。

  3. 运行上面的命令。它启动您的 $ EDITOR

  4. 在<$ c $之前替换 pick c> C 和 D 压扁。它将把C和D融入到B中。如果你想删除一个提交,那么就删除它的一行。

  1. Don't use git-rebase on public (remote) commits.
  2. Make sure your working directory is clean (commit or stash your current changes).
  3. Run the above command. It launches your $EDITOR.
  4. Replace pick before C and D by squash. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆