# [PATCH] Allow "git cancel" to change branches

3 messages from 2005-04-21 to 2005-04-21. Participants: Matthias Urlichs, Petr Baudis, Pavel Roskin.
Thread: https://gitlist.dev/t/200

## Matthias Urlichs, 2005-04-21 13:31

Subject: [PATCH] Allow "git cancel" to change branches
Message-ID: <E1DObsr-0006Au-MA@server.smurf.noris.de>
URL: https://gitlist.dev/e/E1DObsr-0006Au-MA%40server.smurf.noris.de

```
"git cancel" may not be named correctly for this job, but it does almost
everything you'd need for switching between one branch and another
within a repository, so...

Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>

--- f29be8140c5f1175052ec96ad2fa2b2901fd6ba5/git  (mode:100755 sha1:5f23301eb97a0fadd505a6e9cc851e98741a512a)
+++ 42a073eb6b5bb397a3e8768a032463a7fa02e6b9/git  (mode:100755 sha1:557122dfb05580e4af2c55767f3d6f92b9110edd)
@@ -28,7 +28,7 @@
 	add		FILE...
 	addremote	RNAME RSYNC_URL
 	apply				< patch on stdin
-	cancel
+	cancel		[NAME]
 	ci, commit	[FILE]...	< log message on stdin
 	diff		[-p] [-r FROM_ID[:TO_ID]] [FILE]...
 	export		DESTDIR [TREE_ID]
Index: gitcancel.sh
===================================================================
--- f29be8140c5f1175052ec96ad2fa2b2901fd6ba5/gitcancel.sh  (mode:100755 sha1:a78cf8ccab98861ef7aecb4cb5a79e47d3a84b67)
+++ 42a073eb6b5bb397a3e8768a032463a7fa02e6b9/gitcancel.sh  (mode:100755 sha1:2fc3e522132ef6a5f71352ab67005c93b5efc04f)
@@ -9,6 +9,9 @@
 # Basically, this is the opposite of git commit in some sense.
 #
 # Takes no arguments and the evil changes from the tree.
+# 
+# ... actually, if you do give it an argument, it'll switch the HEAD to
+# that branch -- or create a new one.
 
 [ -s ".git/add-queue" ] && rm $(cat .git/add-queue)
 rm -f .git/add-queue .git/rm-queue
@@ -29,6 +32,11 @@
 	fi
 fi
 
+if [ "$1" ] ; then
+	test -f .git/heads/$1 || cp .git/HEAD .git/heads/$1
+	ln -sf "heads/$1" .git/HEAD
+fi
+
 rm -f .git/blocked .git/merging .git/merging-sym .git/merge-base
 read-tree $(tree-id)
 

```

## Petr Baudis, 2005-04-21 16:05

Subject: Re: [PATCH] Allow "git cancel" to change branches
Message-ID: <20050421160526.GB30991@pasky.ji.cz>
URL: https://gitlist.dev/e/20050421160526.GB30991%40pasky.ji.cz
In-Reply-To: <E1DObsr-0006Au-MA@server.smurf.noris.de>

```
Dear diary, on Thu, Apr 21, 2005 at 03:31:24PM CEST, I got a letter
where Matthias Urlichs <smurf@smurf.noris.de> told me that...
> "git cancel" may not be named correctly for this job, but it does almost
> everything you'd need for switching between one branch and another
> within a repository, so...

NO. That is something completely different, although technically it can
look similar.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

```

## Pavel Roskin, 2005-04-21 20:00

Subject: Re: [PATCH] Allow "git cancel" to change branches
Message-ID: <1114113609.29603.24.camel@dv>
URL: https://gitlist.dev/e/1114113609.29603.24.camel%40dv
In-Reply-To: <E1DObsr-0006Au-MA@server.smurf.noris.de>

```
Hi, Matthias!

On Thu, 2005-04-21 at 23:31 +1000, Matthias Urlichs wrote:
> "git cancel" may not be named correctly for this job, but it does almost
> everything you'd need for switching between one branch and another
> within a repository, so...

This functionality is badly needed, but "git cancel" should probably
remain what it is.

> +if [ "$1" ] ; then
> +	test -f .git/heads/$1 || cp .git/HEAD .git/heads/$1
> +	ln -sf "heads/$1" .git/HEAD
> +fi

Considering that the patch is essentially just this block of code, it
could be (in the first approximation) a separate command, e.g. "git
switch", that would call "git cancel" if needed.

But let's consider the fact that "git cancel" removes all local changes.
That's quite a serious side effect.  I don't always want to remove local
changes when I switch between branches in CVS.  Many users would prefer
git to do a merge.

I think that "git track" needs to be redesigned.  There are at least
three properties of the working directory (related to branch tracking)
that users may want to change:

1) Where new revisions are pulled from.  It could be more than one
branch (ideal implementation - with several copies of rsync run
simultaneously).

2) What branch is "checked out" to the working directory, i.e. what
branch would "git cancel" restore.

3) Whether new changes are merged automatically.

I suggest following syntax:

git track -b WORKING-BRANCH [--cancel] [--active|--passive]
[TRACK-BRANCH...|--notrack]

--cancel would cancel changes rather than merge when the current branch
changes.

--active enables automerge, --passive disables it

Empty list of branches to track should not disable tracking.  Only
--notrack should do it.

Then your "git cancel BRANCH" would become:
git track -b BRANCH --cancel

-- 
Regards,
Pavel Roskin


```
