How to Reorder Commits (rebase) with TortoiseGit

这一生的挚爱 提交于 2019-12-05 05:40:21

You are on the right track. Force Rebase is the option you need to use. After you see the commits using the Force Rebase option, select a commit and use the Up/Down buttons to re-order your commits. Press the Start rebase button after you have ordered them as desired.

As regard to why you need to select Force Rebase; Rebase is usually done when you want base your current branch off a newer commit. Since your current branch is already based on the commit that you selected, there is nothing to rebase. In your case, you are simply trying to reorder your commits instead of rebasing. There is nothing wrong in using rebase for that. Just need to select Force Rebase explicitly.

Samuel

This is a workaround solution. Here's what I found:

Definition of upstream and downstream: Definition of "downstream" and "upstream"

Definition of FETCH_HEAD: Search for "what is FETCH_HEAD in git" in Google.

Can I use git command line tools with TortoiseGit?: Can I use command-line Git tools and TortoiseGit simultaneously?

How to reorder commits with git: http://blog.dennisrobinson.name/reorder-commits-with-git/

In this blog post he suggests to use:

git rebase -i HEAD~3

I used

git rebase -i <SHA_of_oldest_commit>

instead. This will provide you with a list of commits from the head to SHA_of_oldest_commit. To reorder the commits I just reordered the lines like I wanted them and saved and closed the file.

I was not able to reorder the commits in TortoiseGit even with the help of answers above. Finally I end up with installing Source Tree with much better UI where you can reorder history with just one click (Rebase children of Hash interactivelly...) by Down and Up buttons.

Here's the full steps from following geoji's answer.

  1. Open TortoiseGit "Show log" at the root of the repository
  2. Right click a commit that isn't the head and select "Rebase "master" onto this..."
  3. On the Rebase dialog that comes up. Change Upstream to "FETCH_HEAD"
  4. Check "Force Rebase"
  5. Your commit history should now show up inside the Rebase dialog
  6. Click a commit you want to move and use the "Up" & "Down" buttons
  7. After the commits are ordered as you want, press "Start Rebase"
  8. It will change the commit hashes for every commit that has to be moved to for the reorder
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!