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?
There are three commands with similar names: git reset , git restore and git revert .
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.
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
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.
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:
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.
git reset --hard cannot be undone
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:
git reset
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:
git gc
(by default, this prunes unreachable objects that are at least 2 weeks old)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With