简体   繁体   中英

In Git, how can I reorder (changes from) pushed commits?

I have a repository with a single ( master ) branch:

a > b > e > f > g > c > d

It turns out that I need the changes in c and d (two commits toward the end of the history so far) to occur earlier, so that I'd have:

a > b > c > d > e > f > g

Everything's been pushed. I understand I'm not supposed to rebase pushed commits, so what can I do?

Here's a quick and dirty solution that doesn't change history:

  1. Use git revert to remove each commit from the branch.
  2. Use git cherry-pick to reapply the commits in the order which you want.

Push these changes. This lets you change the order of the commits without changing the history.

You cannot reorder pushed commits without git push -f . If this repository is shared between you and other guys, then you shouldn't do anything. If this is your own repo or it's on your own branch, use git rebase -i <hash of a> , then reorder the commits as you want, then git push -f .

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