git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Allow "git cancel" to change branches

From
Matthias Urlichs <smurf@smurf.noris.de>
Date
Apr 21, 2005, 13:31 UTC
Message-ID
<E1DObsr-0006Au-MA@server.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)
 
Next: Petr Baudis
Message 1 of 3 in “Allow "git cancel" to change branches”
  1. Allow "git cancel" to change branchesMatthias Urlichs, Apr 21, 2005
  2. Petr BaudisApr 21, 2005
  3. Pavel RoskinApr 21, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.