jonas / tig

Text-mode interface for git
https://jonas.github.io/tig/
GNU General Public License v2.0
12.29k stars 604 forks source link

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

Open MartyLake opened 1 year ago

MartyLake commented 1 year ago

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 commented 1 year ago

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

krobelus commented 1 year ago

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)

MartyLake commented 1 year ago

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