Saturday, January 4, 2020

Rewriting git history

Git makes it possible to edit documents (typically code files) in a number of ways.

(I will use the following terminology: A git repository contains commits, where each commit contains changes to one or more documents. A commit is a container for changes, and has a unique ID and an associated commit message with a description of what/why changes were made.)

Scenarios where I modify commits, and particularly where I modify the history of commits:
  • Undo a particular commit, but leave the history of that the commit has been there and that the commit was undone later.
  • Undo a commit, and remove the history that the commit was ever there.
  • Reorder commits, in order to push selected commits to other people, but leave some commits for me to continue working on and refining.
  • Reorder commits, in order to make the sequence of commits more logical.
  • Split a commit into two or more commits.
  • Collect two or more commits into one commit.
  • Move a commit from one branch to another, if I would like to use it for coming release or on some other feature work.
  • Apply my commits on top of new commits from other people, such that I can base my commits on a version that is known to work.
  • If I started committing on top of a version that is later shown to have errors, I would like to change and instead put my commits on top of a version that I know has no errors.

No comments: