threads / discuss / 8824

How to create & switch to a branch after changes have already been made?

Subject: How to create & switch to a branch after changes have already been made?

## tl;dr

4 messages between Jul 3, 2007 and Jul 3, 2007.

replies: 3people: 2as markdown or json

Patrick Doyle· Jul 3, 2007, 02:18 UTC · lore

Suppose, hypothetically speaking, one were a long time user of CVS who converted to subversion in the last 18 months or so, and who never really understood branches and merging because the syntax was so obtuse and because the projects this hypothetical person had worked were short lived enough that (s)he never really needed to create a branch.

Now suppose this hypothetical person was working on a new project, decided to use git as the project's version control system, got halfway through changing a bunch of files, wanted to commit them as they were, since they worked, but were ugly as sin, and wanted to clean them up before committing them back to the main line of development.

I would tell that hypothetical person, "Gee, it sounds like a branch is exactly what you need here". Unfortunately I don't know how to tell the person to do the equivalent of a "svn switch" when the local repository has been modified.

$ git branch newbranch
 that works, but
$ git checkout newbranch
complains that an untracked file would be overwritten by the merge
(since one of the things that this hypothetical person may have done
would have been to do a "git mv somefile someotherfile").

What would you suggest I say to this person other than "get in the habit of creating a new branch _any_ time you start something new".

--wpd
Patrick Doyle· Jul 3, 2007, 02:49 UTC · re: Patrick Doyle · lore

Re: How to create & switch to a branch after changes have already been made?

Hmmm... One thing I might tell the hypothetical person is to temporarily delete or rename the new version of "somefile", so that the merge could complete with problems, and then recreate or rename it back. That would probably allow the hypothetical person to continue his/her work.

--wpd
Johannes Schindelin· Jul 3, 2007, 11:10 UTC · re: Patrick Doyle · lore

Re: How to create & switch to a branch after changes have already been made?

Hi,
On Mon, 2 Jul 2007, Patrick Doyle wrote:
> Hmmm... One thing I might tell the hypothetical person is to temporarily 
> delete or rename the new version of "somefile", so that the merge could 
> complete with problems, and then recreate or rename it back. That would 
> probably allow the hypothetical person to continue his/her work.
You could also say "git checkout -f newbranch".

Ciao, Dscho

Patrick Doyle· Jul 3, 2007, 14:04 UTC · re: Johannes Schindelin · lore

Re: How to create & switch to a branch after changes have already been made?

The real problem was that I did a
$ git-mv somefile somefile.new

and then created a new version of "somefile". When I temporarily renamed it, all of the given suggestions worked. Thanks.

--wpd

← back to recent threads