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

[PATCH] git-gui: Fast staging/unstaging of hunks/lines

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Apr 5, 2010, 09:01 UTC
Message-ID
<7ed246d74b2ea872a4af3b99d519590ab17ffefc.1270457921.git.bert.wesarg@googlemail.com>

This adds a shortcut to stage/unstage hunks or a range of lines. Which is done on a mouse button 1 release event and holding the control key in the diff view. If there is currently a selection only the selected lines will be staged/unstaged. Otherwise the hunk will be staged/unstaged.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui/git-gui.sh |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 7d54511..e65a0e6 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -3452,6 +3452,22 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
 }
 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
 
+# applies/reverses hunks or lines on button-1 release
+proc immediate_apply_hunk_or_lines {x y} {
+	global current_diff_path file_states
+	set ::cursorX $x
+	set ::cursorY $y
+
+	set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
+	if {$has_range} {
+		apply_range_or_line $::cursorX $:cursorY
+		do_rescan
+	} else {
+		apply_hunk $::cursorX $::cursorY
+	}
+}
+bind $ui_diff <$M1B-ButtonRelease-1> {immediate_apply_hunk_or_lines %x %y}
+
 # -- Status Bar
 #
 set main_status [::status_bar::new .status]
-- 
1.7.0.3.418.gf56ac.dirty
Next: Bert Wesarg
Message 1 of 6 in “git-gui: Fast staging/unstaging of hunks/lines”
  1. git-gui: Fast staging/unstaging of hunks/linesBert Wesarg, Apr 5, 2010
  2. Bert WesargApr 11, 2010
  3. Johannes SixtApr 11, 2010
  4. Bert WesargApr 12, 2010
  5. Johannes SixtApr 12, 2010
  6. Bert WesargApr 12, 2010

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.