Skip to content

Editing your commits afterwards

Jintram edited this page Jun 6, 2011 · 11 revisions

Backing up

Before doing anything it's quit convenient to use the command:

$ git branch backup

To create a branch that you can return to in case everything goes wrong.

Using Rebase

With the git rebase option, you can easily inspect all commits you have made, and rewrite history. An excellent guide on how to do this can be found here: http://help.github.com/rebase/.

Don't forget to use, aside from the -i option, also the -p option, this helps avoiding merging problems.

Issues

I encountered a few issues when running rebase:

Branch lost

Suddenly, rebase "forgot" on which branch I was. I resolved this by using checkout, in my case, for the branch develop:

    $ git checkout develop

Cherry-picking failure

I got an error message:

    Automatic cherry-pick failed.  After resolving the conflicts,
    mark the corrected paths with 'git add <paths>', and
    run 'git rebase --continue'

As I concluded from http://anarchogeek.com/2008/08/01/git-you-are-in-the-middle-of-a-conflicted-merge/, what should resolve this issue, is:

+ Find out which files are causing the error. See 

        $ git status -uno

    Then look at the top of the output.

+ These files have conflicts in them. Check if everything is all right by editing the files. If there are conflicts, one can notice this because git added both options it wants you to choose from to the file, and separated them by an obvious syntax. Edit & save.

+ Just resubmit these files by using 

        $ git add <affected_file>

+ Continue with rebase (git rebase --continue).

Incorrect behaviour with removed/added files

Also, the rebase appears to function incorrectly when you've added and removed files. My solution was to simply add the files rebase was complaining about. (git-add <path_to_annoying_file>.)

"Working tree is dirty"

Also, simply add the files reported as being at fault.