tig icon indicating copy to clipboard operation
tig copied to clipboard

Do we have something like "custom patch" in tig?

Open MartyLake opened this issue 2 years ago • 3 comments

Hey, I stumbled upon a demonstration of lazygit, most of it I could already do with tig.

There was this concept called "custom patch" https://github.com/jesseduffield/lazygit/wiki/Directly-Changing-Code-Stored-In-Commits#lazygit-solution , where one has this temporary diff space and shortcut command to apply the patch to a former commit.

If I had to do it with vanilla git, I would do git add -p, then git diff --staged > patch.diff, then git rebase -i %(commit), then edit the TODO to edit this commit (this I don’t know how to do programmatically), then git apply patch.diff and finally git rebase --continue.

I wonder how it could be emulated in tig, specifically this rebase interactive+edit todo in one script.

Best,

MartyLake avatar Apr 18 '23 13:04 MartyLake

I don’t know how they do it, but you can do "custom patch" of commits that you have already done.

MartyLake avatar Apr 18 '23 13:04 MartyLake

Tig doesn't have dedicated support for this feature yet; I think it would be a nice feature. In the diff view, pressing u could add the selected hunk to a per-commit index. It should be possible to add this special index to an earlier or later commit, or create a separate commit for it.

For the time being, I suggest using git-revise, another 3rd party tool. I sometimes use these bindings to split commits:

bind generic avc >git revise --cut %(commit)
bind generic avC >git revise --cut %(commit) -- %(file)

the second one extracts only from the selected file (though that PR is not merged yet)

krobelus avatar Jun 03 '23 09:06 krobelus

@krobelus Thank you very much, I never heard of git revise before, will definitely try to use it !

MartyLake avatar Jun 05 '23 15:06 MartyLake