Check if specific file in git repository has changed

前端 未结 4 825
面向向阳花
面向向阳花 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:41

    You can pass a file or directory name to git diff to see only changes to that file or directory.

    If you're "writing a batch file" then the --exit-code switch to git diff may be particularly useful. eg.

    git diff --exit-code test

    or:

    git diff --exit-code path/to/source/dir

    Which will return 1 if there are changes to the file named test (or any other specified file or directory) or 0 otherwise. (Allowing a script to branch on the result.)

    To see the names of the changed files only (and not a complete diff) use --name-only xor you can use -s to get no output at all, but just the exit code.

提交回复
热议问题