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

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

 



Yubin Ruan <ablacktshirt@xxxxxxxxx> writes:

> I understand this. I just suggest that git add some warning in case some users
> are not aware of this, as it does when , on branch 'issue', 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
>  
> in this situation, 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

That does not have much to do with "are commits the same?".  If
'master' and 'issue' branches are pointing at different commit, as
long as they record the same content at the path "lala.txt", you can
check out between these branches freely, as we can do so without
having to resort to merging the edit the user made to the working
tree to the different contents of "lala.txt".

There already is an indication that you have local modification in
the working tree when we check out another branch (you would have
seen "M lala.txt" when you did a "checkout" of another branch while
you have local changes to the path).  

Because it is a quite commonly used feature that you can checkout
another branch and carry local changes with you, making it error out
like we do when the branches record different contents for the
locally changed paths when we do not have to would be a bad change
that hurts productivity of users who do use Git correctly, which
would mean that we need to make it an opt-in feature. 

But to help "some users are not aware of this" situation, an opt-in
"feature" would not help all that much.  The same number of lines in
the documentation to tell end-users how to toggle on such a "safety"
feature can be spent to teach them that their local changes in the
working tree do *not* belong to any particular branch, and as soon
as it is understood, the user would be OK.

So...





[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]