How can I join two pushed commits?

2019-09-07 17:38发布

How can I join two pushed commits?

For example: I have a commit fixing a typo and a commit changing a text file. I want to join both and keep only the one which says "changing a text file" on the commit log.

How can I do it?

标签: git github
1条回答
Summer. ? 凉城
2楼-- · 2019-09-07 18:13

Generally, you can use git rebase -i and fixup to rewrite the history and merge commit 2 into commit 1.

Because you already pushed the changes, beware that it is generally not recommended to rewrite the history after the changes has been pushed to a remote repository, because other clients may have already downloaded the changes and you may cause troubles with future updates.

If you are fully aware of what you are doing, use rebase to rewrite the history, and push the changes with the --force flag: git push -f.

查看更多
登录 后发表回答