开发者

Repull changes in git

I made a mistake and i pulled down changes, and i closed my text editor and did save all. So, all the changes got overwritten. Is there anyway to undo my changes or force开发者_运维问答 a repull and overwrite my changes?

Please?


You should look into:

git reset --hard

The general idea is to reset your local repository to HEAD. Any tracked files will be replaced with the ones in HEAD.


If I understand you correctly, most files are now reflecting the HEAD, whereas some random subset (whichever you had open in your editor) is based on commit $OLD_COMMIT plus your changes.

To throw away all your changes and force your working copy to reflect the HEAD, simply do git reset --hard. If you want to salvage your edits, here's what you can do:

First, find out which files got changed by your text editor using git status. Then, run git reflog to figure out the SHA1 of $OLD_COMMIT. Then, run

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

Check that patch looks OK, and run git reset --hard to throw away all changes in your working copy. Then carefully try to apply the patch using the patch command on top the HEAD. Voila!


See also How do I discard unstaged changes in Git?; use git stash to stash the changes. You can delete the stash if you don't need to keep the changes;

git stash save
git stash drop
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜