gitversion-controlgit-mergegit-cherry-pickgit-cherry

Git - How to filter commits while using "git cherry"


I wonder if there is a way to filter only commits to be applied when we use,

git cherry dev

On other words, lets assume above command produces output below,

- 33d5713b613f56938f23f8f61c55e63c34a92720
+ fe77980a11d85ee3a14d45274b0b6db4af8b6574
- 8e642df428532339adee523234da3ce6c1def989
+ 0a747f984d3244e9b5f1b6922d77b0ea5c34f9e0
- 0e3a730cd57bd6898fd444c75bf802c0cbf8000a
+ 40f157ad996bc15b46aa0f25db4f1c4fa3bf3e29

But I am interested to see only outputs like below,

+ fe77980a11d85ee3a14d45274b0b6db4af8b6574
+ 0a747f984d3244e9b5f1b6922d77b0ea5c34f9e0
+ 40f157ad996bc15b46aa0f25db4f1c4fa3bf3e29

that started with + sign.


Solution

  • Plus | grep ^+.

    git cherry dev | grep ^+
    

    grep ^+ means "to match the lines that start with the symbol +".

    If you'd like to remove +/-, there are many solutions. Here are some of them.

    git cherry dev | grep ^+ | awk '{print $NF}'
    git cherry dev | grep ^+ | awk '{print $2}'
    git cherry dev | grep ^+ | cut -d' ' -f2
    git cherry dev | grep ^+ | sed "s/+ //"
    git cherry dev | grep ^+ | tr -d "+ "