here are my branches

aleksey@aleksey:~/Downloads/NTZ/FittingRoom$ git branch -a develop feature/addfriendsblock * feature/getcontacts remotes/origin/develop remotes/origin/master 

I created a feature/getcontacts and worked in it, then made a commit (the work was not finished) ... Then I forgot to switch to feature/addfriendsblock and continued working in the current branch ...

Now I need to switch to the feature/addfriendsblock and commit the latest additions in it, since they do not belong to the current feature/getcontacts , but I get this message

 error: Your local changes to the following files would be overwritten by checkout: Application/src/main/AndroidManifest.xml Please, commit your changes or stash them before you can switch branches. 

But I do not need to commit the latest changes to the current branch. I need them in feature/addfriendsblock , how to do it?

    2 answers 2

    If you only need to commit uncommitted data, but to a different branch, you can do so. First we give the git stash command. She gets diff changes, save it in a special "pocket" and remove them from the branch. Now you can easily switch to another branch - git checkout feature/addfriendsblock . In the new branch we do git stash apply - now changes will be obtained from the "pocket" and applied to the new location (if anything, they will remain in the pocket). It is possible that there will be conflicts - they will need to be resolved. After that the code can be checked and committed.

    • 3
      Plus the -k flag if changes in untracked files. - D-side
    • @ D-side, but why -k because if the changes are not monitored, then they will remain there after switching branches ... or not? - Aleksey Timoshchenko
    • one
      @AlekseyTimoshchenko in the case when in the target branch these files are still tracked and git nervous to switch :) - D-side

    git checkout --merge feature/addfriendsblock

    Then you will need to merge the changes in the Application/src/main/AndroidManifest.xml file

    • Your answer with "AndroidManifest.xml" looks like something strange. Either you are both in the same room (or communicate via a separate communication channel), or a duplicate. - KoVadim
    • one
      @KoVadim What's so strange? The file name I took from the error message that is given in the question. - Pavel Mayorov