Branch x Checkout x Automatic Merging for master

5

Help!

If someone has gone through this or knows how to help, thank you.

  • I created a branch: git branch <xxxx>
  • switch to new branch: git checkout xxxx
  • I changed a file line inside the xxxx
  • I returned to the master branch: git checkout master
  • Scare == > the changes made to the xxxx branch appear in master
  • Output from the command git checkout master :

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

    You are doing merge automatically. Is this normal or was it an installation error? Does anyone know to disable if it is an error?

    EDIT: Guys, thank you for the help, but it's still unclear.

    I was sure that the changes to my xxxx branch would only appear in my master branch when I ran the git merge xxxx command, which was not the case.

    Look, that by simply swapping a branch, it made the automatic merge and it's exactly that automatic merge     

    asked by anonymous 07.07.2016 / 19:11

    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 because it will discard any changes made without "commit". For more information read the manual: git reset --help .

    As Felipe Avelar recalled, you can also save your changes to stash rather than simply discard 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, as stash might get pretty long over time. Read his manual, too: git stash --help .

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

    $ git checkout HEAD -- .
    

    Happy gitting.

        
    07.07.2016 / 19:40
    1

    The code you modified is not yet part of the master branch. It is currently in the form of modified code, but is not in staging or repository (either local or remote).

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

  • Return to branch xxxx : git checkout xxxx
  • Add your changes: git add .
  • Make your changes: git commit -m "(sua justificativa das alterações)"
  • Done, the changes you've made are only in the xxxx branch. To confirm this, see the differences between the branches :

    git diff xxxx..master
    
        
    12.07.2016 / 11:03