git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] Add warning when git discard changes on another branch?
@ 2017-05-07 23:35 Yubin Ruan
  2017-05-08  3:05 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Yubin Ruan @ 2017-05-07 23:35 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-05-08  6:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-07 23:35 [RFC] Add warning when git discard changes on another branch? Yubin Ruan
2017-05-08  3:05 ` Junio C Hamano
2017-05-08 11:18   ` Yubin Ruan
2017-05-08  3:41     ` Junio C Hamano
2017-05-08  4:19       ` Junio C Hamano
2017-05-08 12:27         ` Yubin Ruan
2017-05-08  6:07           ` Junio C Hamano
2017-05-08 14:10             ` Yubin Ruan
2017-05-08 12:01       ` Yubin Ruan

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).