Since all you need is the exit code from the command, you can redirect stdout and stderr to / dev / null:
git show HEAD~1:some_file > /dev/null 2>&1
Exit code 0 means the file exists.
You can use this whole line in your Ruby system call:
exit_code = system("git show HEAD~1:some_file > /dev/null 2>&1")
For those who do this in Bash, you can get the exit code as follows:
git show HEAD~1:some_file > /dev/null 2>&1 if [ $? -ne 0 ]; then
source share