emacs-devel
[Top][All Lists]
Advanced

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

Re: Git question: when using branches, how does git treat working files


From: Yuri Khan
Subject: Re: Git question: when using branches, how does git treat working files when changing branches?
Date: Thu, 29 Oct 2015 08:25:26 +0600

On Thu, Oct 29, 2015 at 5:53 AM, Alan Mackenzie <address@hidden> wrote:

>> David Kastrup also suggested to commit your changes before switching
>> branches, I wonder why you ignored his advice.
>
> It wouldn't work well for me.  The word "commit" has a meaning,
> something like "hand over on a permanent basis".  When you make a
> "commitment", you are pledging your honour that you will stand behind
> what you have committed.  What "commit" _doesn't_ mean is "temporarily
> store because there's nowhere better".  Of course there are ways of
> undoing a commit if it was done by mistake.  But routinely to commit to
> something with the intention of repudiating it later is an abuse.  It is
> the sort of thing politicians do.

In Git, committing is actually *the* easiest solution for the general
problem of tracking uncommitted changes per-branch.

In fact, “git stash” does just that: It creates two new commit objects
(one for the working copy state, the other for the staging area state)
on an unnamed branch starting at your current commit, and records the
hash of the second of those commits in .git/refs/stash and in
.git/logs/refs/stash.

The former file is just a pointer (reference) to the last stash made.
The latter is the list of all existing stashes, typically used in
stack discipline (but “git stash pop” accepts an optional argument
specifying which stash to pop).

A repository browser such as “gitk --all” will show you stashes at the
commits they were made from.


Your solution of making a diff file will also work. It will also be a
non-Git reimplementation of an existing Git feature (stashing), and
will have all its deficiencies (tracking difficulties) and then some
(e.g. an external diff file does not automatically state which commit
it was made from).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]