←back to thread

131 points tomschafer | 4 comments | | HN request time: 0.212s | source
1. CGamesPlay ◴[] No.42152656[source]
Since we're all giving replacements to this, nobody's mentioned my preferred one, so: use git add's patch mode. On a clean worktree, do the search/replace in bulk. Then use `git add --patch` to selectively add the good replacements and skip the bad ones. Finally, `git checkout -- .` to throw away all the bad ones. The nice part about this is that it's not much to remember. If you can make a global search and replace, and you can use `git add --patch` (which is useful loads of times), you can do a selective search and replace by combining them.

As far as this actual tool: the demo GIF is way too fast-paced to show what's going on. A better demo would maybe search "ring", have 10 or so results instead of pages and pages, and show how you can unselect "spring" matches which were unintentionally caught.

replies(3): >>42156267 #>>42160088 #>>42164463 #
2. fragmede ◴[] No.42156267[source]
be very careful with

    git checkout .
it will eat your changes changes if you yolo it.
3. augusto-moura ◴[] No.42160088[source]
Pretty neat trick, I will definitely use it in the future

But it only works in git repositories. Sometimes you need to search and replace on non-git repositories, for those cases Scooter might be the answer

4. pabs3 ◴[] No.42164463[source]
The `git gui` command is a nice-ish graphical alternative to `git add -p` and `git checkout` btw. You can even stage and discard individual lines. There are of course lots of other ones, but the TCL/Tk one is quite featureful.