Branch x Checkout x Merging automatico for master

Asked

Viewed 589 times

6

Help!

If anyone’s been there or knows how to help, I’ll thank you.

  1. created a branch: git branch <xxxx>
  2. changed to new branch: git checkout xxxx
  3. I changed a file line inside the branch xxxx
  4. I returned to the master branch: git checkout master
  5. Thread ==> changes made to branch xxxx appear in the master

Out of command git checkout master:

$ git checkout master
M       WebContent/_footer.jsp
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

Is doing the merge automatic. Is this normal or was it an installation error? Does anyone know how to disable if this is a mistake?

EDIT: Guys, I appreciate the help, but it’s still unclear.

I was sure the changes in my branch xxxx would only appear on my branch master when I executed the command git merge xxxx, what was not the case.

You see, by simply switching branches he did the merge automatic and that’s exactly merge automatic that I don’t want, someone else to help?

2 answers

4

This is normal and automatic. To avoid this kind of problem you should discard the changes made using the command:

$ git reset --hard HEAD

Run this command very carefully as it will discard all changes made without "commit". For more information read the manual: git reset --help.

As Felipe Avelar recalled it is also possible to save your changes made in stash instead of simply discarding them. The command for this is:

$ git stash save 'descrição das alterações feitas'

But use this only if the changes are worth it, because the stash can be quite long over time. Read his manual, too: git stash --help.

Another option would be to use the checkout for this, if you have not put the changes in addition stage, yet:

$ git checkout HEAD -- .

Happy gitting.

  • Or he can commit the changes or play pro stash too. (:

  • 2

    @Felipeavelar Well remembered, I added in the reply.

  • 1

    Or git checkout -- :/

  • @Masterid You’re right, added.

  • This isn’t automatic! You must not have made the branch change... Are you sure you created the branch correctly? Sure it was for the right branch to make the change?

  • @Yes, it’s automatic because he didn’t commit of the change. Try: git reset --hard HEAD && git checkout -b foo && echo foo > arquivo-ja-versionado-previamente && git checkout master && git status

Show 1 more comment

1

The code you modified is not yet part of the branch master. It is for the time being listed as code modified, but is not in the staging or in the repository (whether local or remote).

So you can keep changes only in the branch xxxx, do the following:

  1. Go back to the branch xxxx: git checkout xxxx
  2. Add your changes: git add .
  3. Committee your amendments: git commit -m "(sua justificativa das alterações)"

Okay, the changes you made are just in the branch xxxx. To confirm this, see the differences between the two branches:

git diff xxxx..master

Browser other questions tagged

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