e40 e40 - 1 month ago 5
Git Question

How can I tell, from a script, if "git cherry-pick" fails?

If the cherry-pick fails due to a merge conflict, it just returns an exit status of 0.

Please don't tell me about

--abort
. I need to detect, in a script, if the original cherry-pick command fails.

Using git version 1.8.3.1 on CentOS 7.2.

EDIT: my script was doing the cherry-pick in an
if !
and I didn't exit properly in the
then
clause with a non-zero exit. Sorry for the noise.

Answer

$? is the return code for a process run in bash.

$ ls /dev/null/foo
ls: /dev/null/foo: Not a directory
$ echo $?
1