5

It seems like I have inadvertently modified my git config such that when I switch from branchA to master all changes are automatically merged to master. This happens without either my committing in branchA or my merging to master. In the past if I tried to switch branches after modifying a tracked file and without committing, I got "the uncommitted changes, can't switch branches" message, but now I'm unable to induce that behavior. Something has changed with my git config, but I have no idea what it might be. Does this sound familiar to anyone?

Any help is greatly appreciated.

Ubuntu 10.10
git 1.7.1
github.com

here's my git config -l:

giggle.main-window-maximized=false
giggle.main-window-geometry=993x731+318+160
giggle.history-view-vpane-position=223
giggle.main-window-view=HistoryView
giggle.file-view-vpane-position=153
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=**************************************
branch.master.remote=origin
branch.master.merge=refs/heads/master
submodule.config/shared_capistrano.url=******************capistrano.git
submodule.vendor/plugins/authentication_client.url=********************.git
branch.dev.remote=origin
branch.dev.merge=refs/heads/dev
branch.1.3.9.remote=origin
branch.1.3.9.merge=refs/heads/1.3.9
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user508546
  • 421
  • 5
  • 12
  • Are you talking about your _uncommitted_ changes being carried across to the master branch, or something else? – Koterpillar Jun 13 '11 at 23:19
  • You can do `git config -l` to list your config. Post it here (excluding anything secret), maybe someone can find something strange. – Paŭlo Ebermann Jun 13 '11 at 23:26
  • possible duplicate of [Modified files and git branches](http://stackoverflow.com/questions/246275/modified-files-and-git-branches) – Chris Johnsen Jun 14 '11 at 07:33
  • thanks, yeah that sounds like a duplicate of what i'm seeing, but my real issue is the warning message. i understand now why the file appears in master after the change, but i still don't understand why i no longer get the warning "you have un-committed changes, can't switch branches". that was a very useful warning to have. – user508546 Jun 14 '11 at 15:11
  • @user508546: You only see the “can’t switch branches” message if the uncommitted changes conflict with changes made in the destination branch. `mkdir temp && cd temp && git init && echo foo master1 >foo && git add foo && git commit -mm1 && git branch other && echo foo master2 >>foo && git add foo && git commit -mm2 && git checkout other && echo foo other1 >>foo && git checkout master` produces `error: Your local changes to the following files would be overwritten by checkout: …`. It works if you drop the conflicting “m2” from *master*: `git branch -f master master~ && git checkout master`. – Chris Johnsen Jun 14 '11 at 20:59
  • @user508546: Also, it is inaccurate to think about “files appearing in master after [switching branches]”. The changes only exist in your working tree (and/or index). They are not actually associated with any branch until you commit them. When switching branches, `git checkout` preserves any uncommitted changes (unless you give it `-f`/`--force`). If a modified file is different at HEAD and your destination branch, then `git checkout` gives the error in my previous comment because it can not 100% safely preserve the changes. – Chris Johnsen Jun 14 '11 at 21:16

1 Answers1

6

When you are switching branch and the files are only locally modified, Git will not give you the warning / message ( and will merge the changes into the other branch). For example, you have your repo on master, create a branch temp, have a local modification on the file. Now, when you switch to master you won't get the message. If on the other hand you makes changes in temp and commit them ( that is temp diverges from master ) and then you have local modifications, it will give you that message when you switch to master

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • thanks for the reply. here's my scenario more precisely: both branches exist remotely and locally, all of the files are already tracked. i make a change in branchA to a tracked file, then immediately issue "git checkout master" and no warning message and the changes are reflected in master. i believe i used to get the warning in exactly this scenario, but now i do not. – user508546 Jun 14 '11 at 15:03