History
History
7 min read
This area brings together everything that changes commits that already exist. Use these features to tidy up a branch before opening the merge request, take a fix from one branch to another, undo a commit that went in wrong or move the branch back to an earlier point.
The features fall into two groups, and the difference matters when the commits have already been pushed:
| Group | Features | What happens to the commits |
|---|---|---|
| Rewrite | interactive rebase, edit message, drop and move commit, commit surgery, move changes between commits, reset, squash commits | The commits involved and all the ones after them get new SHAs. If they were already on the remote, the next push has to be forced. |
| Add | cherry-pick, revert, squash merge | New commits go on top. Nothing that already exists changes, so the push is a regular one. |
| You want to… | Use | Page |
|---|---|---|
| Tidy up several commits at once: reorder, combine, change messages, drop | Interactive rebase | Interactive rebase |
| Change the message of an older commit | Edit commit message… | Edit message, drop and move commits |
| Remove a commit from the branch | Drop commit… | Edit message, drop and move commits |
| Swap two neighboring commits | Move commit up / Move commit down | Edit message, drop and move commits |
| Fix a commit in the middle of the branch with what is staged | Commit as fixup of…, Amend this commit with the staged changes…, Absorb… | Commit surgery |
| Split a large commit into several | Split commit… | Commit surgery |
| Take a commit out of the middle and bring its changes back to the stage | Uncommit (bring the changes back to the stage)… | Commit surgery |
| Take a file, a hunk or a few lines from one commit to another | Move to commit… or drag | Move a file, hunk or lines between commits |
| Copy commits from another branch to the current one, or to another branch without checkout | Cherry-pick | Cherry-pick |
| Cancel out a commit that has already been pushed, without rewriting anything | Revert commit | Revert |
| Move the current branch to another commit | Reset (soft, mixed or hard) | Reset |
| Combine neighboring commits into one, or bring a whole branch in as one commit | Squash N commits…, Squash merge X into Y… | Squash |
- A commit's menu (right-click in the graph, or Shift+F10 with the commit selected): reset, revert, edit message, surgery, move changes, drop, move up or down, interactive rebase and cherry-pick. A branch's menu has the history items (reset, revert, edit message, surgery, drop, move and interactive rebase) for its tip commit, plus "Interactive rebase of…" and "Squash merge…". The full list is in Context menus.
- The selection menu (Ctrl+click and Shift+click on several commits in the graph): squash, drop, cherry-pick, revert and interactive rebase of the chosen commits. See Multiple selection.
- The "Commit surgery" bar, in the commit box, right below "Commit options": fixup, absorb and applying pending fixups.
- A commit's diff: the Move… button on each hunk and Move lines to commit… for the chosen lines.
- Dragging in the graph: a commit onto a branch label does a cherry-pick; onto another commit, a rebase. See Dragging branches and commits.
When a menu item doesn't apply to that commit, it shows up disabled and, in most cases, the text itself says why, in the "Label — reason" format. Example: "Split commit… — merge commit".
Versora considers "pushed" every commit that is already on some known remote branch (the
refs/remotes/* from the last fetch). Before rewriting, it warns you:
- In interactive rebase and commit surgery, each pushed commit gets a badge: on remote in the rebase, pushed in surgery.
- The confirmation dialogs say how many commits are already on the remote, for example: "This rewrites history, and 2 of the commits involved are already on the remote: you'll need to force push afterward, and anyone who already pulled those commits will have to adjust."
- Edit message and drop commit show the general warning: "This rewrites history: this commit and the ones after it get new IDs. If they were already pushed to the remote, you'll need to force push."
Versora never force pushes on its own after a rewrite. To send it, use Force push… (protected
by --force-with-lease and --force-if-includes), explained in
Force push.
Caution
Rewriting a branch that other people have already fetched forces each of them to adjust their local
copy. On shared branches (such as main or release/*), prefer the features that only add
commits: revert and cherry-pick.
Almost every feature in this area goes into Ctrl+Z as a single operation. Undo takes the branches (and, when the feature kept a copy, the files) back to the state they were in before. The general rules:
| Situation | What to do |
|---|---|
| The operation finished without stopping | Ctrl+Z undoes it; Ctrl+Shift+Z redoes it. |
| The operation stopped at a conflict or at a stop for editing | Abort (on the changes panel's operation bar) puts everything back as it was. While it's stopped, Ctrl+Z doesn't undo the operation itself ("A rebase is in progress. Finish or abort it (in the changes panel) before undoing."), only the steps taken during the stop: resolving a file in the conflict editor, staging a conflicted file, a discard. |
| An operation that Versora started (interactive rebase, rebase, cherry-pick, revert, merge) stopped and you finished it later, with Continue, through the commit box or even from the terminal | It goes into Ctrl+Z as a whole, as if it had never stopped: undo goes back to the state before it. The steps taken during the stop leave the undo history at that point. If you used Abort, nothing goes in: the repository is already back to what it was. |
| A commit surgery or move-between-commits operation stopped and you continued until the end | It goes into Ctrl+Z when it finishes, as a single operation. |
| The operation stopped and finished, but Versora didn't start it (it came from the terminal) | It doesn't go into Ctrl+Z. To go back, use the reflog. The exception is a stopped merge concluded in Versora (with Continue, through the commit box or with Finish the merge without hooks): it goes in as a whole anyway. |
| You touched the repository after the operation (another commit, terminal, another program) | Undo refuses: "The repository has changed since this operation, so it isn't safe to undo it automatically." |
The Ctrl+Z history keeps each repository's 40 most recent operations and lasts while Versora is open. The details are in Undo and redo, and the list over time, in Timeline.
Commit surgery, moving changes between commits, cherry-pick without checkout and the conflict
preview for cherry-pick and revert need git 2.40 or newer, because they use
git merge-tree --write-tree --merge-base to simulate the operation in memory. With an older git,
a warning bar at the top of the window lists what is unavailable, and commit surgery warns: "Commit
surgery needs git 2.40 or newer (this one is 2.39). Update Git for Windows."
Interactive rebase, edit message, drop, move up or down, reset, revert, regular cherry-pick and squash merge don't depend on that version. The minimum recommended version, with which everything works, is also 2.40; the Preferences › Operations page shows the installed version under "Git version".
- Interactive rebase: one screen to reorder, edit messages,
stop for editing, combine (squash and fixup) and drop several commits, run in a single
git rebase -i. - Edit message, drop and move commits: quick edits to a commit from the menu, without opening the rebase screen.
- Commit surgery: targeted fixup, applying pending fixups, absorb, amending a commit in the middle, squashing into the previous one, uncommit and splitting a commit, with the branch stack along with it.
- Move a file, hunk or lines between commits: taking part of a commit to another commit on the branch, or to a new commit.
- Cherry-pick: copying one or more commits to the current branch or, by dragging, to another branch without checkout.
- Revert: cancelling out one or more commits with new commits.
- Reset: moving the current branch to another commit, in soft, mixed and hard modes.
- Squash: combining neighboring commits into one and doing a local squash merge of a branch.
- Conflicts: the conflict editor and stopped operations (continue, skip, abort).
- Undo and recover: Ctrl+Z, timeline, stash and how to recover lost work.
- Branch stacks: how the branches above follow a rewrite.
- Worktrees: cherry-picking and moving commits to another worktree.
- Inspection: reflog, bisect and the commit overlap analysis.