What are some actions in Git What is difficult or impossible to undo?

One of the strengths of Git is that since it works with pointers, it is relatively easy to undo a wide range of tasks, including deleting a commit or committing> or creating and deleting remote branches . In many cases, all you really need to do is correctly reset the current pointer to the HEAD branch of the pointer to the right place and voila, undo the step. This covers a fairly wide range of cases.

Besides deleting the entire repository or bad clicking, what is the most non-trivial action that is either impossible to undo or extremely difficult to undo in the standard Git repository?

+5
source share
4 answers
  • git cleanDeletes unprocessed files. They cannot be restored using git.

  • Merging with a dirty work tree can lead to something that is difficult to repair.

In short, things that are not tracked by git cannot be repaired with git. Everything else can be restored.

+3
source

An example of a difficult action to undo would be:

git branch -D some-unmerged-branch-such-as-master
git gc --prune=now --aggressive

The first removes the link to some commits. The second removes all commits without links.

I hope this question is just a matter of idle curiosity, and not you want to spare someone a repo, but because of the redundancy inherent in distributed version control, I'm not too worried.

+3
source

" ", , git, git stash, git stash pop git stash. :

git init /tmp/trash && cd /tmp/trash     # make a new repo
echo A > A                               # create a file
git add A
git commit -m "Initial commit"           # add and commit it
echo B > A                               # ... now change it
git stash                                # ... and stash it
echo C > A                               # and change it and commit it again
git add A
git commit -m "Another commit"
git stash pop                            # now pop the stash

pop A , , git stash . , , , . , git stash drop , , .

, stash , : , , , . , .

+3

In my experience, the most common irreversible action that people perform is git reset --hard. When many people write git reset, --hardit seems too natural when they really need only reset, perhaps, s --keep.

0
source

All Articles