I wish I had a fork in Git - can I go back?

This is a usage example that has appeared a couple of times. Since I (unfortunately) am not used to branches for each function, sometimes I start work on a task, make a couple of commits, and then say "Shit ... it's harder than I thought ... I would like for me to create a branch three commits ago. "

At this point, I can return to a specific commit and branch from there, but this leaves these new commits on the host, and not on the feature branch. I could choose any commit, or maybe reinstall it on a new branch, but that still leaves the branch on the host.

How can i do this?

+6
source share
1 answer

The shortest thing:

  • ,
  • reset , :

, , , :

git branch feature-A
git reset --hard HEAD~2

.

+11

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


All Articles