[英]How to squash 7 pushed commits into one in to 1 in git?
I have tried multiple ways to squash my remote repo commits but didnt get it right. 我已经尝试了多种方法来压缩我的远程repo提交,但没有把它弄好。 I want to squash them all and make it one .
我想把它们全部压扁并制成一个。 Below is the list of commits.
以下是提交列表。 Below is the summary of my pull request to upstream (which lists 7 commits).
下面是我对上游的拉取请求的摘要(列出了7次提交)。 I want to list only one instead of 7.
我想只列出一个而不是7个。
git reset --soft HEAD~7
git add --all
git commit
git push --force
First, reset git index to before the commits you want to squash. 首先,将git index重置为要压缩的提交之前。 Use
--soft
so that git only resets the index and doesn't touch your working directory. 使用
--soft
以便git只重置索引并且不会触及您的工作目录。 Then create a commit as usual. 然后像往常一样创建一个提交。
Another way is to use squash
- i other work interactive rebase
另一种方法是使用
squash
- 我的其他工作interactive rebase
In order to do a git squash follow those steps: 为了做一个git squash,请按照以下步骤操作:
# X is the number of commits you wish to squash, in your case 7
# In this interactive rebase there can be more that 7 commits if
# there was a merge in one of them
git rebase -i HEAD~X
Once you squash your commits - choose the s
for squash = it will combine all the commits into a single commit. 一旦你压缩你的提交 - 选择
s
为squash =它会将所有提交组合成一个提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.