Check if specific file in git repository has changed

前端 未结 4 826
面向向阳花
面向向阳花 2021-02-05 03:59

I am novice in dealing with git, but I have a repository that contains a file named \'test\'. I want to check if that specific file has changed. Is there anyway to do that?

4条回答
  •  死守一世寂寞
    2021-02-05 04:38

    As it was correctly mentioned in the answer of Peter Lundgren,

    git commands are intended to be run against a local repository,

    so git clone is likely to be called anyways.

    On the other hand, if you need to check if you want to trigger some specific CI step, you might find useful something like this in your script:

    if git diff --quiet $COMMIT_HASH^! -- . ':!test'; then
       echo "No significant changes"
    else 
       echo "There are some significant changes, let's trigger something..."
    fi
    

    --quiet disables all output of the program and implies --exit-code (see git documentation).

    Reference this answer for more details regarding the pattern at the end of the expression.

提交回复
热议问题