Does git reset -hard use the correct idea instead of checking when you have unpublished commits?

I helped the employee today on his machine and partially helped us in troubleshooting the problems of returning to the previous commit. He had an unpublished commit, i.e. his branch was one message in front of the remote branch. I thought he was going to call git checkout, instead I looked horrified when he made a note about the unpublished SHA1 commit, and then continued to call git reset --hardat the target commit that we had to explore. After some time, he returned to his previous state, causing another hard reset back to the marked SHA1, which worked. He told me that in this situation he always used hard reset.

Then I had the following questions:

  • Is this operation protected from data loss? Is there a chance that his fixation will be lost?

  • Wouldn't this operation leave a chatty reference to fixing it, which can be removed with runnning git gc? Sometimes I see git doing housekeeping operations in large repositories that start automatically after calling some unrelated command. Can one of these operations destroy the commit?

  • Is there a way to restore a fix if a note is lost?

+4
source share
2 answers

Let them have the order:

Is this operation protected from data loss? Is there a chance that his fixation will be lost?

No and no, in that order. Or maybe “not yet” is better for a second answer.

Git reset --hard () : , , , ; , ; , .

, , . , Git , ( Git, , / ).

git reset git reset --mixed. . , ( ). , . , , ( Git): , .git git worktree add -ed ).

" " git reset, git reset --soft. . , , , , ORIG_HEAD.

ORIG_HEAD, , git reset, , , . , - HEAD, - 30 Git reflogs. , ORIG_HEAD, reflog, .

(Reflogs --bare, .)

, runnning Git gc?

ORIG_HEAD, . , gc. ORIG_HEAD reflog ( ) , , , .

, [ ] ?

Reflogs ( ORIG_HEAD) . , git fsck --lost-found ( ) lost-found .git, , git gc -ed. , git add -ed, ( " ", --lost-found ).

, , git reset -

- git checkout . " ", , : git checkout <branch>, HEAD. , , , git bisect, , . git bisect - () , , () , - , . , , bisect , .

, : git bisect run , . git bisect , , - "" "".

+4

? ?

, . , , . , , , .

, runnning git gc? git , . ?

reflog, git gc, , .

, ?

git reflog .

PS

, , . , , . git . , , .

+1

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


All Articles