automatically stash save/pop changes on git rebase?

前端 未结 5 1772
再見小時候
再見小時候 2021-01-30 20:40

my git workflow uses rebase a lot. I always fetch upstream changes (the main repo i forked from) and then merge to my branches, and then rebase to remove useless (to me :D) merg

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 21:47

    You may use an external tools called git-up, which does exactly what you say for all branches. This will also help you keeping a clean history graph.

    I've used for some years and it works pretty well, especially if you are not a git expert. If you add auto-rebasing feature you should know how to properly recover from failing rebase (continue, abort, ...)

    Install

    Open a shell and run:

    sudo gem install git-up
    

    Configuration

    Open your global config file (~/.gitconfig), and add the following:

    [git-up "fetch"]
        all = true    # up all branches at once, default false
        prune = true  # prune deleted remote branches, default false
    [git-up "rebase"]
        # recreate merges while rebasing, default: unset
        arguments = --preserve-merges
        # uncomment the following to show changed commit on rebase
        # log-hook = "git --no-pager log --oneline --color --decorate $1..$2"
    

    See the official documentation for more options.

    Invocation

    If everything is configured well, just run:

    git up
    

    This is (roughly) equivalent of executing the following:

    git stash
    git fetch --all
    [foreach branch]
        git rebase --preserve-merges  /
        git merge --ff-only 
    [end foreach]
    git checkout 
    git stash pop
    

提交回复
热议问题