From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Git question: when using branches, how does git treat working files when changing branches? Date: Wed, 28 Oct 2015 20:44:57 +0100 Message-ID: <87vb9q6ame.fsf@fencepost.gnu.org> References: <20151028192017.GC2538@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1446064642 31940 80.91.229.3 (28 Oct 2015 20:37:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Oct 2015 20:37:22 +0000 (UTC) Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 28 21:37:21 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZrXT5-0006Ov-CK for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 21:37:11 +0100 Original-Received: from localhost ([::1]:40626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrXT4-000182-Nh for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 16:37:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrXT1-00017w-It for emacs-devel@gnu.org; Wed, 28 Oct 2015 16:37:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrXT0-0002pX-FF for emacs-devel@gnu.org; Wed, 28 Oct 2015 16:37:07 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:55400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrXT0-0002pS-Bz; Wed, 28 Oct 2015 16:37:06 -0400 Original-Received: from localhost ([127.0.0.1]:40986 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.82) (envelope-from ) id 1ZrXSz-0001Hk-Ri; Wed, 28 Oct 2015 16:37:06 -0400 Original-Received: by lola (Postfix, from userid 1000) id 313D4DF873; Wed, 28 Oct 2015 20:44:57 +0100 (CET) In-Reply-To: <20151028192017.GC2538@acm.fritz.box> (Alan Mackenzie's message of "Wed, 28 Oct 2015 19:20:17 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:192828 Archived-At: Alan Mackenzie writes: > Hello, Emacs. > > I want to start using git branches, so as to be able to work on several > distinct things at the same time. > > My question is, how does git handle working files (which haven't been > committed) when changing from one branch to another. I've spent the > usual two hours searching the fine manuals without turning up a clear > explanation. > > One thing that worries me is that the same command "git checkout" is > used to change branches and to revert changes to a file. So it seems > plausible that each time I swap to a different branch I'm in danger of > irrevocably losing existing changes to source files. > > So, what happens to to changes in the working directory when changing > branches? > 1. git refuses to change branches because there are uncommitted changes. > 2. git changes branches, discarding all uncommitted changes. > 3. git changes branches, leaving the changes from the previous branch in > the working directory. Either 1 or 3, depending on whether the difference between the two branches overlaps with the uncommitted changes or not. When Git can just keep the uncommitted changes without conflict, it does that. This comes in rather handy when you start doing some work, then figure out that you really should have started a new branch. You can then just checkout/create the new branch and ultimately commit there. > What I really want to happen is > 4. git maintains uncommitted changes separately in each branch. Nope. There is only one index and one work directory. Just commit them. You can also do "git stash" for saving index/work directory on a stack and use "git stash pop" for getting them back out again later when you switch back to your branch, but stashes are not tied to a particular branch either. It's usually just easier to do git commit -m "wip" -a and have a commit with message "wip" (work in progress) on the branch where it belongs. You can fix that commit up later with git commit --amend in order to both fix the commit message as well as adding more changes to it. -- David Kastrup