如何将所有 git 提交压缩为一个? [英] How to squash all git commits into one?

查看:31
本文介绍了如何将所有 git 提交压缩为一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整个存储库压缩到第一次提交?

How do you squash your entire repository down to the first commit?

我可以重新调整到第一次提交,但这会给我留下 2 次提交.有没有办法在第一个之前引用提交?

I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first one?

推荐答案

也许最简单的方法是创建一个具有当前工作副本状态的新存储库.如果您想保留所有提交消息,您可以先执行 git log >original.log 然后在新存储库中为您的初始提交消息编辑它:

Perhaps the easiest way is to just create a new repository with current state of the working copy. If you want to keep all the commit messages you could first do git log > original.log and then edit that for your initial commit message in the new repository:

rm -rf .git
git init
git add .
git commit

git log > original.log
# edit original.log as desired
rm -rf .git
git init
git add .
git commit -F original.log

这篇关于如何将所有 git 提交压缩为一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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