简体   繁体   中英

Is it possible to squash two pushed commits from the same branch into a single commit with git?

I want to make 2 commits into one commit so if later in the future I have to revert that commit I don't have to remember what were the two commits I have to revert and also because those two commits are referring to the same change it would be a good idea to squash them into one.

So, I've read some ideas on how to do it like this one:

Squashing pushed commits into one commit but the problem is that with this approach I can only squash the commits that are close by each other. So I was wondering if there's a better way to approach this.

You can use the rebase command to move the two commits so that they are next to each other, and then squash them together. rebase -i is useful for this, because you can select the commits that you want to move around in a text editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM