Why do local changes seem to exist equally in both branches?

gerrit

I have different branches in my git repo. I checkout a new branch and apply a change. When I checkout back to my master branch, it still shows the change. Similarly, when I stage changes for commit in the new branch, then checkout the master branch, it again shows those changes as staged.

Why do changes in my branch regrid-more-flexible-times seem to be shown (either staged or unstaged) even when I switch back to my branch master? See below for an illustration.

$ git branch
* master
  regrid-more-flexible-times
  regrid-sst
$ git checkout regrid-more-flexible-times
Switched to branch 'regrid-more-flexible-times'
$ git status
# On branch regrid-more-flexible-times
nothing to commit (working directory clean)
$ vim regridworkflow.py
$ git status
# On branch regrid-more-flexible-times
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   regridworkflow.py
#
no changes added to commit (use "git add" and/or "git commit -a")

So far so good. I've made changes in my branch regrid-more-flexible-times. Now I need to head back to master to access the codebase without any changes.

$ git checkout master
M       mms/src/main/python/regridworkflow.py
Switched to branch 'master'
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   regridworkflow.py
#
no changes added to commit (use "git add" and/or "git commit -a")

Huh? Why does branch master show the unstaged changes I made while on branch regrid-more-flexible-times? Perhaps it is only aware of differences after I stage them?

$ git checkout regrid-more-flexible-times
M       mms/src/main/python/regridworkflow.py
Switched to branch 'regrid-more-flexible-times'
$ git add regridworkflow.py
$ git status
# On branch regrid-more-flexible-times
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   regridworkflow.py
#
$ git checkout master
M       mms/src/main/python/regridworkflow.py
Switched to branch 'master'
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   regridworkflow.py
#

...and why does branch master show the changes I staged while on branch regrid-more-flexible-times?

My aim is to be able to work an changes while on branch regrid-more-flexible-times, but to be able to checkout the master branch which does not have those changes. Why does the workflow above not do so, and how should I do instead to achieve this?

choroba

I've made changes in my branch regrid-more-flexible-times.

No, you've made changes to your wokring copy.

why does branch master show the changes I staged while on branch regrid-more-flexible-times?

There's only one staging area per working copy. They don't exist for each branch. See git stash on how to save changes without committing them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do != and <> both exist in postgres?

From Dev

How to merge changes to both branches

From Java

How to prune local tracking branches that do not exist on remote anymore

From Dev

Git: How do I list local branches that are tracking remote branches that no longer exist?

From Dev

Switching branches each with local changes

From Dev

Why do both struct and class exist in C++?

From Dev

Why do git commits exist on my local clone/directory but not on GitHub?

From Dev

Subversion : Why do my project in subversion "branches", "tags", "trunk", and "wiki" folders does not exist?

From Dev

Why do I have to stash / commit my changes before switching branches?

From Dev

Prune origin branches that do not exist on upstream anymore

From Dev

Prune origin branches that do not exist on upstream anymore

From Dev

Do both branches and tags both -- literally speaking -- refer to commits?

From Dev

Do both branches and tags both -- literally speaking -- refer to commits?

From Dev

git merge changes both local and remote branch

From Dev

Why do local variables that reference a global object seem to violate function scope?

From Dev

Java: Writer.write() and Writer.append() are the same; why do they both exist?

From Dev

Git local changes are inadvertently applied across all branches

From Dev

Create a branch for a new feature on local branch only or on both local and remote branches?

From Dev

Both branches are behind each other. How do I merge the two branches?

From Dev

Why do both /var/log/Xorg.0.log and /var/log/Xorg.1.log exist on my system?

From Dev

Why do both /var/log/Xorg.0.log and /var/log/Xorg.1.log exist on my system?

From Dev

Why does merging these branches do nothing?

From Dev

Keep both local and remote changes after forgetting to pull

From Dev

Keep both local and remote changes after forgetting to pull

From Dev

Why do fields seem to be initialized before constructor?

From Dev

Why do I seem to be stuck in a loop?

From Dev

Why can I still see local modifications after switching branches?

From Dev

Why do scriptlets exist in JSP?

From Dev

Why do hard links exist?

Related Related

  1. 1

    Why do != and <> both exist in postgres?

  2. 2

    How to merge changes to both branches

  3. 3

    How to prune local tracking branches that do not exist on remote anymore

  4. 4

    Git: How do I list local branches that are tracking remote branches that no longer exist?

  5. 5

    Switching branches each with local changes

  6. 6

    Why do both struct and class exist in C++?

  7. 7

    Why do git commits exist on my local clone/directory but not on GitHub?

  8. 8

    Subversion : Why do my project in subversion "branches", "tags", "trunk", and "wiki" folders does not exist?

  9. 9

    Why do I have to stash / commit my changes before switching branches?

  10. 10

    Prune origin branches that do not exist on upstream anymore

  11. 11

    Prune origin branches that do not exist on upstream anymore

  12. 12

    Do both branches and tags both -- literally speaking -- refer to commits?

  13. 13

    Do both branches and tags both -- literally speaking -- refer to commits?

  14. 14

    git merge changes both local and remote branch

  15. 15

    Why do local variables that reference a global object seem to violate function scope?

  16. 16

    Java: Writer.write() and Writer.append() are the same; why do they both exist?

  17. 17

    Git local changes are inadvertently applied across all branches

  18. 18

    Create a branch for a new feature on local branch only or on both local and remote branches?

  19. 19

    Both branches are behind each other. How do I merge the two branches?

  20. 20

    Why do both /var/log/Xorg.0.log and /var/log/Xorg.1.log exist on my system?

  21. 21

    Why do both /var/log/Xorg.0.log and /var/log/Xorg.1.log exist on my system?

  22. 22

    Why does merging these branches do nothing?

  23. 23

    Keep both local and remote changes after forgetting to pull

  24. 24

    Keep both local and remote changes after forgetting to pull

  25. 25

    Why do fields seem to be initialized before constructor?

  26. 26

    Why do I seem to be stuck in a loop?

  27. 27

    Why can I still see local modifications after switching branches?

  28. 28

    Why do scriptlets exist in JSP?

  29. 29

    Why do hard links exist?

HotTag

Archive