#git #commands

git_commands

Internal crate for autorebase

1 unstable release

0.2.0 May 4, 2021
Download history 33/week @ 2023-10-18 23/week @ 2023-10-25 12/week @ 2023-11-01 20/week @ 2023-11-08 12/week @ 2023-11-15 42/week @ 2023-11-22 43/week @ 2023-11-29 18/week @ 2023-12-06 9/week @ 2023-12-13 10/week @ 2023-12-20 37/week @ 2023-12-27 35/week @ 2024-01-03 39/week @ 2024-01-10 31/week @ 2024-01-17 12/week @ 2024-01-24 22/week @ 2024-01-31

107 downloads per month
Used in 2 crates

MIT license

4KB
62 lines

Build Status

Autorebase

Autorebase automatically rebases all of your feature branches onto master. If conflicts are found it will rebase to the last commit that doesn't cause conflicts. By default, branches with an upstream are excluded. You don't need to switch to any branch, the only limitation is that a branch that is checked out and not clean will not be rebased (though I may add that in future).

Here is a demo. Before autorebase we have a number of old feature branches.

Let's autorebase!

This has attempted to rebase all of the branches. demo and readme were successfully rebased onto master. However the other branches had conflicts, so they were not rebased all the way to master. Instead they were rebased to just before the commit that caused the conflicts.

If a commit couldn't be fully rebased due to conflicts, it is marked as such and rebasing it won't be attempted again until its commit hash changes (e.g. to being edited or manually rebased).

Installation

Download a binary release from the Github releases page, or you can run

cargo install autorebase

Usage

Just run autorebase in your repo. This will perform the following actions

  1. Update master, by pulling it with --ff-only unless you have it checked out with pending changes.
  2. Create a temporary work tree inside .git/autorebase (this is currently never deleted but you can do it manually with git worktree remove autorebase_worktree).
  3. Get the list of branches that have no upstream (except with --all-branches), and aren't checked out with pending changes.
  4. For each branch:
    1. Try to rebase it onto master.
    2. If that fails due to conflicts, abort and try to rebase it as far as possible. There are two strategies for this (see below).
    3. If we didn't manage to rebase all the way to master, then mark the branch as "stuck" so it isn't attempted in future. To "unstick" it, rebase manually or add more commits to the branch.

Full usage is:

autorebase
    [--slow]
    [--all-branches]
    [--onto <target_branch>]

<target_branch> is master by default. If you develop on develop you probably want autorebase --onto develop.

There are two strategies to deal with conflicts. The default is fast; --slow selects the slow method. The slow method simply tries rebasing onto master^, master^^, master^^^ and so on until one works or we get to the merge base.

The fast method tries to rebase master onto the feature branch. It counts how many commits succeed, and assumes that these ones don't conflict, and the next commit must be the offending one. Then it aborts the rebase and rebases the feature branch to just before that commit.

The slow method is reliable but slow. The fast method is fast but may be suboptimal in some case, for instance if a conflict is only introduced temporarily.

Limitations

  • It probably won't be able to rebase branches that aren't trees, i.e. branches that contain merge commits. I haven't really tested this.
  • It does everything by running git on the command line rather than through a library like libgit2, which probably isn't super robust.
  • There's no way to manually specify which branches to rebase. I may add an interface like autorebase track my_branch at some point. Maybe.
  • autorebase's worktree is never deleted so it uses up some disk space forever. You can delete it manually if you like.
  • Limited testing!

Dependencies

~0.2–8.5MB
~50K SLoC