Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created a file at /usr/local/git/findsed.sh , with the following contents:</p> <pre><code>find . -name 'githubDirToSubmodule.sh' -exec sed -i '' -e 's/What I want to remove//g' {} \; </code></pre> <p>I ran the command:</p> <pre><code>git filter-branch --tree-filter "sh /usr/local/git/findsed.sh" </code></pre> <p><strong>Explanation of commands</strong></p> <p>When you run git filter-branch, this goes through each revision that you ever committed, one by one. --tree-filter runs the findsed.sh script on each committed revision, saves it, then progresses to the next revision.</p> <p>The find command finds a specific file or set of files and executes (-exec) the sed editor on that file. sed is a command that takes the regex after s/ and replaces it with the string between / and /g (blank in my example). {} is a reference to the files path that was given by the find command. The file path is fed to sed, so that sed knows what to work on. \; just ends the -exec command.</p> <p>Seperating the shell script and command out into seperate pieces allows for less complication when it comes to quotes '' or "".</p> <p><strong>Peculiarities</strong></p> <p>I successfully implemented this on a mac, and apparently sed is a particular (older?) version on macs. This matters, as it sometimes behaves differently. Make sure to do sed -i '' or else it was adding a "-e" to the end of files, thinking that that was what i wanted to name my backup files. -i '' says dont make backup files, just edit the files in place and no backup file needed.</p> <p>Specifying -name 'filename.sh' helped me avoid another issue that I could not solve. There was another file with .sh and that file ended without a newline character. sed for some reason, would add a newline character to the end, despite the 's/blah/blah/g' not matching anything in that file. So instead of figuring out that issue, I just told the find to ignore all other files.</p> <p><strong>Additional commands that work</strong></p> <p>Additionally, I found these commands to work in the findsed.sh file (only one command at a time, not multple, so comment # the others out):</p> <pre><code>find . -name '.publishNewZenPackFromGithub.sh.swp' -exec rm -f {} \; find . -name '*' -exec grep -H PassToRemove {} \; </code></pre> <p>Enjoy!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload