Git rebase : pour diviser un commit

Anne git

Lors du nettoyage de l’historique des commits, on peut avoir envie de diviser l’un d’entre eux.

ATTENTION : ne faire ça que si les commits n’ont pas été poussés dans le dépôt !

C’est très bien expliqué sur StackOverflow, et voilà ce que ça dit au cas où :

  • Perform an interactive rebase including the target commit (e.g. git rebase -i <commit-to-split>^ branch) and mark it to be edited.

  • When the rebase reaches that commit, use git reset HEAD^ to reset to before the commit, but keep your work tree intact.

  • Incrementally add changes and commit them, making as many commits as desired. add -p can be useful to add only some of the changes in a given file. Use commit -c ORIG_HEAD if you want to re-use the original commit message for a certain commit.

  • If you want to test what you’re committing (good idea!) use git stash to hide away the part you haven’t committed (or stash --keep-index before you even commit it), test, then git stash pop to return the rest to the work tree. Keep making commits until you get all modifications committed, i.e. have a clean work tree.

  • Run git rebase --continue to proceed applying the commits after the now-split commit.

Voir aussi :