Sublime Forum

[TIP/TRICK] Create / Apply / Revert a patch of a commit

#1

Hello everyone,

Sharing some customs commands, some of you might find them helpful to externalize/share codes with your co-workers, I frequently use them to paste a complete commit into a Teams/Mail conversation and they ask me how I do this, so here it is.

  • File > Preferences > Browse Package
  • If it does not exists, Create the folder User\
  • Create a blank file called Commit.sublime-menu in User\
  • Create a blank file called Default.sublime-commands in User\
  • Paste the content into each files
  • Reload SublimeMerge

Enjoy the new menus

Commit.sublime-menu

[
  {
      "caption": "Create Patch of Commit '$short_commit…'",
      "command": "git",
      "args": {"argv": ["format-patch", "--no-encode-email-headers", "-1", "$commit"]}
  },  
  {
      "caption": "Create Patch of Commit '$short_commit…' (ignore space)",
      "command": "git",
      "args": {"argv": ["format-patch", "--no-encode-email-headers", "--ignore-all-space", "--ignore-space-change", "-1", "$commit"]}
  },  
  {
      "caption": "Apply Patch…",
      "command": "git",
      "args": {"argv": ["apply", "$text"]}
  },
  {
      "caption": "Apply Patch… (ignore space)",
      "command": "git",
      "args": {"argv": ["apply", "--ignore-space-change", "$text"]}
  },
  {
      "caption": "Revert Patch…",
      "command": "git",
      "args": {"argv": ["apply", "-R", "$text"]}
  },
  {
      "caption": "Revert Patch… (ignore space)",
      "command": "git",
      "args": {"argv": ["apply", "-R", "--ignore-space-change", "$text"]}
  },
	{
		"caption": "-",
	},
]

Default.sublime-commands

[
    {
        "caption": "Create Patch…\tgit format-patch -1",
        "command": "git",
        "args": {"argv": ["format-patch", "--no-encode-email-headers", "-1", "$select_branch", "$select_commit"]}
    },
    {
        "caption": "Create Patch… (ignore space)\tgit format-patch --ignore-all-space --ignore-space-change -1",
        "command": "git",
        "args": {"argv": ["format-patch", "--no-encode-email-headers", "--ignore-all-space", "--ignore-space-change", "-1", "$select_branch", "$select_commit"]}
    },
    {
        "caption": "Apply Patch…\tgit apply",
        "command": "git",
        "args": {"argv": ["apply", "$text"]}
    },
    {
        "caption": "Apply Patch… (ignore space)\tgit apply --ignore-space-change",
        "command": "git",
        "args": {"argv": ["apply", "--ignore-space-change", "$text"]}
    },
    {
        "caption": "Revert Patch…\tgit apply -R",
        "command": "git",
        "args": {"argv": ["apply", "-R", "$text"]}
    },
    {
        "caption": "Revert Patch… (ignore space)\tgit apply -R --ignore-space-change",
        "command": "git",
        "args": {"argv": ["apply", "-R", "--ignore-space-change", "$text"]}
    }
]
1 Like