git-merge-workshops / git-it-right

In this workshop, participants will learn the basics of common Git commands used in various situations. This includes commands which help you examine repo history and state while also learning to manipulate repo history.
5 stars 0 forks source link

Undoing git commit #3

Open bryantson opened 2 years ago

bryantson commented 2 years ago

Undoing commits

image

In this section, we will learn about commands that re-write history and understand when you should or shouldn't use them.

How Commits Are Made

Every commit in Git is a unique snapshot of the project at that point in time. It contains the following information:

Each commit also contains the commit ID of its parent commit.

Safe Operations

Git's data structure gives it integrity but its distributed nature also requires us to be aware of how certain operations will impact the commits that have already been shared.

If an operation will change a commit ID that has been pushed to the remote (also known as a public commit), we must be careful in choosing the operations to perform.

Guidelines for Common Commands

Command Cautions
revert Generally safe since it creates a new commit.
commit --amend Only use on local commits.
reset Only use on local commits.
cherry-pick Only use on local commits.
rebase Only use on local commits.

Reverting a Commit

Warning: Before you reverse the commit, it is a good idea to make sure you will not be inadvertently reversing other changes that were lumped into the same commit. To see what was changed in the commit, use git show SHA.

bryantson commented 2 years ago

Congratulation. You are done with "Undoing git commit" section

mona

Let's move to the next issue