[RFC] Add warning when git discard changes on another branch?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I think it would be better if git can warn use if we switch to another branch
without committing the modification. Git will warn if the modification is based
on a commit different from where the checkout happened.

For example, say I am now on branch 'master' and all files *clean*. Now if I do:
    $ git checkout -b issue
and make some changes to a file:
    $ echo "modification on branch issue" >> lala.txt
and then switch back to branch 'master':
    $ git checkout master
and git can see the changes:
    $ git status
      On branch master
      Changes not staged for commit:
        (use "git add <file>..." to update what will be committed)
        (use "git checkout -- <file>..." to discard changes in working directory)
      
      	modified:   lala.txt
      
      no changes added to commit (use "git add" and/or "git commit -a")
      
Now, if I do "git checkout -- lala.txt", then I will lose that change on branch
'issue' too!!! 

If, on branch 'issue', the changes to 'lala.txt' are based on a commit different
from where the checkout happened, i.e.
     
    on branch 'master'
        |
        |  <-- git checkout -b issue
         \
          \  <-- modification to git happened on a commit different from where
                 the checkout happened

then git would warn us something like this:

    error: Your local changes to the following files would be overwritten by checkout:
    	lala.txt
    Please, commit your changes or stash them before you can switch branches.
    Aborting

So, I think it is better to add some similar warinings if the modification
happened on a commit the *same* as where the checkout happened, i.e.

    on branch 'master'
        |
        |  <-- git checkout -b issue
           <-- modification to git happened on a commit different from where
               the checkout happened

I already lost some of my work by this ...

(p.s please add me to the Cc because I am not in this list)
---
Yubin



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]