From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Steinar Bang 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 21:00:38 +0100 Organization: Probably a good idea Message-ID: 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 1446062413 27417 80.91.229.3 (28 Oct 2015 20:00:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Oct 2015 20:00:13 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 28 21:00:06 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 1ZrWtA-0007Q4-H9 for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 21:00:04 +0100 Original-Received: from localhost ([::1]:40496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrWt9-0000hX-Ms for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 16:00:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrWsv-0000hE-D2 for emacs-devel@gnu.org; Wed, 28 Oct 2015 15:59:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrWss-0001xg-72 for emacs-devel@gnu.org; Wed, 28 Oct 2015 15:59:49 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:47684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrWsr-0001xS-W4 for emacs-devel@gnu.org; Wed, 28 Oct 2015 15:59:46 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZrWsq-00077f-28 for emacs-devel@gnu.org; Wed, 28 Oct 2015 20:59:44 +0100 Original-Received: from cm-84.208.248.210.getinternet.no ([84.208.248.210]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 28 Oct 2015 20:59:44 +0100 Original-Received: from sb by cm-84.208.248.210.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 28 Oct 2015 20:59:44 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 51 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.208.248.210.getinternet.no Mail-Copies-To: never User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (windows-nt) Cancel-Lock: sha1:yux8E6Cng0caSL//m+b4mtgvhuc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:192821 Archived-At: >>>>> Alan Mackenzie : > So, what happens to to changes in the working directory when changing > branches? > 1. git refuses to change branches because there are uncommitted changes. If the branch you change to wants to modify one of the files you have local changes in, git will abort the branch change with the message: error: Your local changes to the following files would be overwritten by checkout: filename Please, commit your changes or stash them before you can switch branches. Aborting > 2. git changes branches, discarding all uncommitted changes. Not by default, but using "-f" or "--force" will allow you to change branch while overwriting local changes. > 3. git changes branches, leaving the changes from the previous branch in > the working directory. If the branch change doesn't overwrite any of the files where you have local changes, this is what will happen. > What I really want to happen is > 4. git maintains uncommitted changes separately in each branch. > I suspect 4. is not the way git works. Correct. > So, how do I best simulate 4.? git stash git checkout some-branch git stash pop > I would like to be able to move freely between git branches without > suffering stupid restrictions like having to worry about preserving > changes in the working directory. Is there some variant of "git stash" > which might do what I want? You mean, automatically...? Dunno. I mostly just try changing the branch, and revert to git stash git checkout some-branch git stash pop if git complains about local changes being overwritten.