gitrebase

Git: auto-fixup a commit in a feature branch


When I am done with a feature, often what I would like is to auto-fixup a commit followed by a force-push to a remote origin before a merge to master.

I end up rebasing on top of master so I can fixup a commit, because I found a tiny thing I want to change and I don't want that change as a separate commit. So I rebase interactively, I fixup the last commit, then I force push. Is there a way to do that in one step?


Solution

  • Assuming you want to fixup the last commit, you could just amend that commit. After authoring your changes, just issue:

    $ git commit -a --amend --no-edit
    

    You'll still have to force-push, though.

    Here's a breakdown of git commit options used above:

    -a, --all: 
    Tell the command to automatically stage files that have been modified and 
    deleted, but new files you have not told Git about are not affected.
    
    --amend: 
    Replace the tip of the current branch by creating a new commit.
    
    --no-edit: 
    Use the selected commit message without launching an editor. 
    For example, `git commit --amend --no-edit` amends a commit without changing 
    its commit message.