Can't find work in Git branch after checking another branch

I was on the main branch, and I ran git checkout -b ui. During the week, tons of work continued, at the end of which I ran:

git add .
git commit -am 'ui'

git checkout master
git merge ui
git push

Then I switched to the branch I was working on earlier - git checkout uploads. At this moment, everything I did in the ui branch was lost. It is not listed in git log, but git reset --hard HEAD^returns me to the branch to the "ui" branch. How does this happen?

I managed to recover most of them by looking at the reflog and returning to the "ui" commit, but I wonder why this happens?

+3
source share
2 answers

, , git ( git checkout), , . :

git branch

... master, ui uploads.

ui, :

git log ui

, git reset --hard HEAD^ master, ui, , ( master ) :

  • master
  • ui

^ , - , HEAD^2. , , git reset --hard , , master. ( , , , , .)

, ui, master, , , , ui any . , , , - , uploads , .

+7

, , . , , ui , uploads. , ui uploads. :

  • master uploads: git merge master
  • Rebase uploads master: git rebase master

uploads.

+3

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