Adjusting local branches before committing

Asked

Viewed 42 times

0

I’m new to Git and I need to make a quick adjustment to my branches.

I started an activity in a wrong local branch "X". I would like to migrate the changes to a local branch "Y" to give commit from "Y" and undo changes in X.

How do I create a Y branch from local X before undoing X changes?

I’m using Visual Studio 2017 with the Git extension for VS.

1 answer

0


First you create a new branch:

git branch Y

It will already be with the modifications made to the X branch. If you want to check if everything is right, do a git checkout Y and tests the modifications made.

In the X branch for you to return to the last commit, just use:

git revert HEAD~1

Recalling that the HEAD~1 will only return a commit(last) if you use HEAD~2 will go back to two commits and so on.

  • Nice... I didn’t know that creating Y would already bring the X changes. It worked here. Thank you so much!

  • If banch Y was already created, just do a git merge. Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.