All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yubin Ruan <ablacktshirt@gmail.com>
To: git@vger.kernel.org
Subject: [RFC] Add warning when git discard changes on another branch?
Date: Mon, 8 May 2017 07:35:14 +0800	[thread overview]
Message-ID: <20170507233512.GA9332@HP> (raw)

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

             reply	other threads:[~2017-05-07 22:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-07 23:35 Yubin Ruan [this message]
2017-05-08  3:05 ` [RFC] Add warning when git discard changes on another branch? 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170507233512.GA9332@HP \
    --to=ablacktshirt@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.