Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the destructive commands in git?

Tags:

git

I read that Git mainly adds information about the repository's history, trying to remember every change made, but that there are also commands that make irreversible changes.

What are the commands that I should really pay attention to and avoid using wrongly because there is no turning back?

like image 478
Riccardo Galli Avatar asked Apr 28 '10 09:04

Riccardo Galli


People also ask

How many commands are there in git?

There are three commands with similar names: git reset , git restore and git revert .

What is git reset head?

The git reset HEAD~2 command moves the current branch backward by two commits, effectively removing the two snapshots we just created from the project history. Remember that this kind of reset should only be used on unpublished commits.

What are the 10 Git commands every developer should know?

10 Git Commands Every Developer Should Know. 1 1. Git clone. 2 2. Git branch. 3 3. Git checkout. 4 4. Git status. 5 5. Git add. More items

What is the use of gitgit Branch Command?

git branch: Git branch command is used to list down all the branches that are locally present in the repository. Git branch [branch-name]: This is used to create a new branch.

How to use Git checkout?

Git checkout This is also one of the most used Git commands. To work in a branch, first you need to switch to it. We use git checkout mostly for switching from one branch to another. We can also use it for checking out files and commits. There are some steps you need to follow for successfully switching between branches:

How to push a git branch to a new repository?

To push the new branch into the remote repository, you need to use the following command: 3. Git checkout This is also one of the most used Git commands. To work in a branch, first you need to switch to it. We use git checkout mostly for switching from one branch to another. We can also use it for checking out files and commits.


2 Answers

git reset --hard cannot be undone

like image 87
Johnno Nolan Avatar answered Sep 21 '22 01:09

Johnno Nolan


There are two kinds of "destructive" here -- commands that are destructive to your git history and commands that discard changes in your working copy.

Commands that discard work tree changes:

  1. git reset
  2. git checkout

As others have mentioned, the combination of the reflog and the fact that git objects don't immediately get discarded (unless you turn on automatic cleanup) means that you can usually undo operations like git reset/rebase/merge.

These commands, though, actually discard git objects, eliminating the ability to undo:

  1. git gc (by default, this prunes unreachable objects that are at least 2 weeks old)
like image 31
Mike Seplowitz Avatar answered Sep 20 '22 01:09

Mike Seplowitz