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?
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 branchregrid-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.
Comments