Is there a generic git "undo" command?

Looking at some of the most popular questions ever asked in SO, it seems like git errors are a fairly common problem. He answered all these questions well, and the git commands were quite brief, but I was wondering if there are git or implementation plans in future releases - the general git cancellation command . This command will literally undo exactly any git command you recently executed.

Change . As for the specifics, I mean that git undo looks at the state of the repository right before typing your erroneous command, and returns it to an exact copy of what that state was

For example, if I did git add -all , then I typed something like git undo , git will disconnect all the files that were just delivered, and the repository will look identical to what it was before I typed my git to add everything.

Also here is a great resource summarizing git cancel commands

+4
source share
2 answers

It would be very easy to make such a team yourself.

export STORE=/home/me/.git_backup 
mkdir $STORE
export ROOT=/home/me/src/somegitrepos
alias git='tar czf /$STORE/state.tar.gz -C $ROOT . ; /usr/bin/git'
alias git-undo='rm -rf $ROOT/* $ROOT/.??* ; cd $ROOT/ ; tar xzf /$STORE/state.tar.gz' 

(Obviously, you need to add reliability, i.e. make sure that $STORE/state.tar.gzexists before rm -rfand supports several different repositories, etc.)

, . . git tar.gz. , FS (, xfs) . ...

, "" git, , ( , tar "" ).

, , git undo:

  • "" , .. git, (, status, log), . , . , ( tar, ).
  • cvs, svn git , git , . , git, "" -. git reset --hard, git (.. ), ( ...).

    git "" (heck, gitk ). , svn... , , , "" git undo .

    , git rebase -i , - " ", (, - , ;)).

+3

, . , .

, , , Qaru - , .

+2

Source: https://habr.com/ru/post/1649207/


All Articles