git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
YRYubin Ruan <ablacktshirt@gmail.com>
Date
May 8, 2017, 12:01 UTC
Message-ID
<20170508120129.GA3540@HP>
In-Reply-To
<xmqqvapc9fsg.fsf@gitster.mtv.corp.google.com>
On Mon, May 08, 2017 at 12:41:03PM +0900, Junio C Hamano wrote:
Show 31 quoted lines
> Yubin Ruan <ablacktshirt@gmail.com> 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).  
That is convincing :)
 
Show 6 quoted lines
> 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. 
I agree.
Show 9 quoted lines
> 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...
> 

--- Yubin

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 9 in “[RFC] Add warning when git discard changes on another branch?”
  1. Yubin RuanMay 7, 2017
  2. Junio C HamanoMay 8, 2017
  3. Yubin RuanMay 8, 2017
  4. Junio C HamanoMay 8, 2017
  5. Yubin RuanMay 8, 2017
  6. Junio C HamanoMay 8, 2017
  7. Yubin RuanMay 8, 2017
  8. Junio C HamanoMay 8, 2017
  9. Yubin RuanMay 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.