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

查看:21
本文介绍了如何在保留更改的同时从 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.

我的提交树看起来像:

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

git awsome-ness [git rebase --interactive] 包含一个例子.

  1. 不要在公开(远程)提交中使用 git-rebase.
  2. 确保您的工作目录是干净的(commitstash 您当前的更改).
  3. 运行上面的命令.它会启动您的 $EDITOR.
  4. squash替换CD之前的pick.它会将 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天全站免登陆