rewriting history
Replacing existing commits with new ones, for example with amend, rebase or reset, which gives them new IDs.
Rewriting commits others have pulled splits the team's history and can lose their work.
In more detail
Commits can never be edited, so any change to an old commit creates a new commit, and new IDs for every commit after it. That is harmless on work only you have, but commits others have pulled then exist in two versions, so the one hard rule is: never rewrite history anybody else has pulled. Pushing rewritten history needs a force push.
Related terms
- git commit --amend — A form of git commit that replaces the most recent commit with a new one, combining its changes with whatever is staged and optionally a new message.
- rebase — Moving a series of commits so they start from a different commit, by replaying each one as a new commit with a new ID.
- interactive rebase — A rebase that first opens a todo list in your editor, letting you reorder, reword, squash or drop commits before they are replayed.
- force push — A push that makes the remote branch match yours even when that throws away commits the remote has.
- git reset — The command that moves the current branch to another commit, and depending on the mode also resets the staging area and working tree.
Taught in
- Recovering And Removing Data With Git — Microsoft Azure DevOps Engineer Expert (AZ-400) Exam Prep
- Installing Git, And Telling It Who You Are — Advanced Git Internals & Distributed Workflows
- What A Commit Really Is — Advanced Git Internals & Distributed Workflows
- Merging: Fast Forward Or A Merge Commit — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Amend, And The One Hard Rule — Advanced Git Internals & Distributed Workflows
- Interactive Rebase: Squash, Reorder, Reword — Advanced Git Internals & Distributed Workflows
- Cherry Picking, Reflog, And Getting Work Back — Advanced Git Internals & Distributed Workflows
- Investigating History: blame, bisect And worktree — Advanced Git Internals & Distributed Workflows
- Tags And Releases — Advanced Git Internals & Distributed Workflows
- Trunk Based Development Versus Git Flow — Advanced Git Internals & Distributed Workflows
- A Copy Of The Backup: etcd — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- Component Sprint: The Reference Build — Kubernetes and Cloud Native Security Associate (KCSA) Exam Prep
- The Pager Command That Opened A Root Shell: sudo, su And Least Privilege — CompTIA Linux+ (XK0-006) Exam Prep