• johnrob 2 months ago

    Once I discovered how git apply can take diff files (or patch files) as input, I stopped using git stash in favor of plain old files. Easier to list and browse the contents of prior edits, also you can grep the files as method of search. I’ve even found myself copying and editing the diffs before applying.

    • OskarS 2 months ago

      That is a very neat trick, I agree.

      I personally approaches stashes as undoable "clean up", and I never have anything really important that I want to save there. If I do have something like that, I just commit with a "WIP <some-descriptive-string>" message and don't push it, then a "git reset --mixed HEAD^" when I want to get back to it.

      However, just FYI: you can "grep" your stashes really easily if you want to. just "git stash list -p" gives you the diffs for all the stashes, by default in "less" where you can search them, but you can pipe it to grep if you want. I somewhat frequently do that with "git log", if I want to know "when did this variable change?" or whatever, just "git log -p" to get the log with diffs in less, then search for whatever it was with a slash.

      • barbazoo 2 months ago

        Oh that’s clever, I’ll try that out. Looks like you could just do a git diff > file.patch.

        Neat.

        • johnrob 2 months ago

          You’ll also want to familiarize with “git apply -3 <file name>”, for when a diff can’t be applied cleanly. It will try “harder” to merge (three way method) and if it still fails it invokes the conflict merge “UX”:

          <<<<<<<<<

          =========

          >>>>>>>>>

          • smcameron 2 months ago

            There's also Neil Brown's "wiggle" program for applying patches that don't apply.

            https://github.com/neilbrown/wiggle

            although on debian based systems I think you can just "apt install wiggle"

            • johnisgood 2 months ago

              What does "applying patches that don't apply" mean exactly?

              I know about wiggle, but I have not used it, to be honest.

              • smcameron 2 months ago

                It means that if you do "patch -p1 --dry-run < some.patch", and it complains that it doesn't apply, wiggle can sometimes apply it anyway, and also, if you do "patch -p1 < some.patch", and it partially applies but with rejected hunks, wiggle can try to apply the rejected hunks.

          • johannes1234321 2 months ago

            git diff an pipe works, but committing and then `git format-patch` can export multiple patches and then includes metadata (commit message, date, author, etc.) which can make reasoning about such files a lot easier. In a plain diff you only got filename as metadata.

          • d3ckard 2 months ago

            Thank you, will try. Useful bit of knowledge.

            • RaoulP 2 months ago

              That’s a great idea, and very timely for me.

            • teeray 2 months ago

              Maybe slightly O/T, but has anyone found a decent way to `git send-email` with email hosts that demand OAuth? (looking at you Outlook and Gmail)

              • ozarker 2 months ago

                I think you could set up postfix to smtp forward to those services. So it could handle the oauth2 and you wouldn’t need to configure your client

                • computerfriend 2 months ago
                  • p_wood 2 months ago

                    I use an app password but https://github.com/AdityaGarg8/git-credential-email apparently supports OAuth with Gmail, yahoo and outlook

                    • arthurmorgan123 2 months ago

                      I tried this with Gmail and Outlook. Works flawlessly and also doesn't need to authenticate frequently. The Authen::SASL thing was a catch though.

                      git-send-email also has some quirks for Outlook which have been recently merged.

                    • mathstuf 2 months ago

                      I use msmtp with a tool from the oauth2-tools repo to do the rotation token dance. Need to register your own app with Google though.

                      • ravetcofx 2 months ago

                        Generating app passwords for those would work.

                        • pm215 2 months ago

                          Yeah, I use an app specific password with Gmail, like the setup suggested by https://git-send-email.io/#step-2

                          Exchange historically had a tendency to mangle emails sent through it (whitespace changes, line wrap, etc), which is obviously bad news for patchmails. I dunno if it's any better these days.

                        • dmarinus 2 months ago

                          davmail supports smtp through outlook(365)

                          • ndegruchy 2 months ago

                            Yeah, I used DAVMail with Emacs+MSMTP+MPOP+notmuch for ages. Works really well, the only occasional thing I had to do was reauthenticate the token, which pops up in a browser window.

                        • palata 2 months ago

                          I like doing it with aerc [1]. It's even possible to use aerc in parallel to another email client. Just open aerc for git-related emails, and that's it!

                          [1]: https://drewdevault.com/2022/07/25/Code-review-with-aerc.htm...

                          • smcameron 2 months ago

                            If you work with git and patches a lot, stgit is worth a look.

                            https://stacked-git.github.io

                            • johnisgood 2 months ago

                              At that point, why not just use Pijul or even Darcs?

                              • smcameron a month ago

                                Because the codebase you're working on is on github?

                                And I think you may underestimate the power of stgit. You can manage thousands of patches concurrently, no problem. If you're a maintainer getting patches from loads of people all the time, this is valuable. stgit has it's origins in quilt, which in turn has its origins in Andrew Morton's patch scripts[1], and I know for a fact that Andrew Morton actually managed thousands of patches at a time for years in his work on the linux kernel, because I once sent him a patch against those scripts, and he complained it was slow because I used an O(n^2) algorithm, which worked fine with a handful of patches, and I asked him how many patches he had, and he told me a number that was multiple thousands, so this isn't a hypothetical example.

                                [1] https://lwn.net/Articles/13518/

                            • kazinator 2 months ago

                              View the e-mail raw in your browser, select all, copy, paste into git apply.

                              Then you don't need that message to be in a file-based inbox that is accessible from your git repo.

                              And in that case you are still likely going to have to copy and paste something to get the correct path.

                              • sircastor 2 months ago

                                It looks like Apple Mail has plugin support, I wonder if you could author a plugin that’d provide a button to apply the diff.

                                • gitroom 2 months ago

                                  [dead]