Here is the script that I want to run using git filter-branch:
#!/bin/bash
if test -e src/unlagged.cpp; then
more +34 src/unlagged.cpp | cat ~/newlic.cpp.txt - > /tmp/unlagged.cpp
cp /tmp/unlagged.cpp src/unlagged.cpp
fi
if test -e src/unlagged.h; then
more +34 src/unlagged.h | cat ~/newlic.h.txt - > /tmp/unlagged.h
cp /tmp/unlagged.h src/unlagged.h
fi
Pretty simple. It takes everything past the first 34 lines of src/unlagged.cpp and src/unlagged.h, concatenates it with the contents of a text file, then writes it out to a temporary file, which is then copied on top of the file I wished to modify. This works great as long as I’m simply running it inside my source tree, as the output of src/unlagged.cpp looks like:
(newlic.cpp.txt)
(everything passed line 34 of src/unlagged.cpp)
However, when I run git filter-branch '/path/to/script.sh' -- --all, the files are modified thusly…
(newlic.cpp.txt)
::::::::::::::
src/unlagged.cpp
::::::::::::::
(entire src/unlagged.cpp)
Where did those colons and the name of the file come from? Why didn’t it actually trim src/unlagged.cpp? I tried the script with #!/bin/sh and got the same result. I’m using git 1.7.7.3, by the way.
Use
tail -n +34instead ofmore +34. You are being interfered with by the interactive nature of more. As an example, runmore +34 src/unlagged.cpp < /dev/nulland you will see the :::::::::: lines.