Discard changes in git

I made a mistake and I pulled the changes and I closed my text editor and saved everything. So, all changes have been overwritten. Is there a way to undo my changes or force to undo and overwrite my changes?

You are welcome?

+3
source share
3 answers

You should learn:

git reset --hard

The general idea is to reset your local repository for HEAD. Any monitored files will be replaced with those specified in HEAD.

+4
source

If you understand correctly, most files now reflect HEAD, while some random subsets (depending on what you opened in your editor) are based on commit $ OLD_COMMIT plus your changes.

HEAD, git reset --hard. , :

, , git status. git reflog, SHA1 $OLD_COMMIT.

git diff $OLD_COMMIT -- enumerate.c every/one.c of/your.c changed/files.c > patch

, patch , git reset --hard, . , patch HEAD. !

+1

. Git?; git stash, . , ;

git stash save
git stash drop
0

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


All Articles