From: Junio C Hamano <gitster@pobox.com>
To: Yubin Ruan <ablacktshirt@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC] Add warning when git discard changes on another branch?
Date: Mon, 08 May 2017 12:05:31 +0900 [thread overview]
Message-ID: <xmqqzieo9hfo.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170507233512.GA9332@HP> (Yubin Ruan's message of "Mon, 8 May 2017 07:35:14 +0800")
Yubin Ruan <ablacktshirt@gmail.com> writes:
> 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!!!
There may be a fundamental misunderstanding here. In Git, changes
you make in the working tree do *not* belong to any branch. The
request "git checkout -- lala.txt" you made in this step does *not*
say "Hey, Git, these changes to lala.txt are not necessary in the
'master' branch". It says "I started editing lala.txt, but it turns
out that I do not need that change at all, anywhere, please remove
it."
If you meant the changes while you were on "issues" branch were not
yet ready to be committed, but now you want to work on "master"
branch without having to worry about these changes, "git stash" may
be a useful tool. Alternatively, you can just create a temporary
commit while on "issues" branch before checking out "master" branch
to work on something else, and when you are ready to continue
working on the "issues" branch, check out "issues" branch and either
(1) start with "reset HEAD^" or (2) just continue working on it and
conclude with "commit --amend".
next prev parent reply other threads:[~2017-05-08 3:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzieo9hfo.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=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.
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).