programing

단일 하위 폴더의 git-status를 얻는 방법은 무엇입니까?

nasanasas 2020. 10. 17. 10:36
반응형

단일 하위 폴더의 git-status를 얻는 방법은 무엇입니까?


내 저장소의 하위 폴더에서 git status를 수행하면 상위 폴더의 상태도 포함됩니다.

git-status를 특정 폴더로 제한하는 방법이 있습니까?


git status .

현재 디렉터리 및 하위 디렉터리의 상태를 표시합니다.

예를 들어,이 트리에서 주어진 파일 (숫자) :

a/1
a/2
b/3
b/4
b/c/5
b/c/6

하위 디렉토리 "b" git status에서 전체 트리에 새 파일을 표시합니다.

% git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   ../a/1
#   new file:   ../a/2
#   new file:   3
#   new file:   4
#   new file:   c/5
#   new file:   c/6
#

그러나 git status ."b"이하의 파일 만 표시합니다.

% git status .
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   3
#   new file:   4
#   new file:   c/5
#   new file:   c/6
#

아래가 아닌이 하위 디렉토리 만

git status ."b"아래의 모든 파일을 재귀 적으로 표시합니다. "b"에있는 파일 만 표시하고 아래에는 표시하지 않으려면 파일 목록 만 (디렉토리 제외)에 전달해야 git status합니다. 셸에 따라 약간 이상합니다.

Zsh

zsh에서는 "glob 한정자"를 사용하여 일반 파일을 선택할 수 있습니다 (.). 예를 들면 :

% git status *(.)
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   3
        new file:   4

세게 때리다

Bash에는 glob 한정자가 없지만 GNU find사용 하여 일반 파일을 선택한 다음 다음과 같이 전달할 수 있습니다 git status.

bash-3.2$ find . -type f -maxdepth 1 -exec git status {} +
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   3
        new file:   4

이 사용 -maxdepthA는 GNU 찾아 확장합니다. POSIX의 발견은 없습니다 -maxdepth,하지만 당신은이 작업을 수행 할 수 있습니다

bash-3.2$ find . -path '*/*' -prune -type f -exec git status {} +
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   3
        new file:   4

일부 배관 명령은 디렉토리를 매개 변수로 사용합니다.

git ls-files -t -o -m aDirectory

모든 파일이 변경되었지만 업데이트되지 않았거나 (스테이지에 추가되지 않음) 추적되지 않은 파일을 제공합니다. 그리고 그것은 디렉토리입니다.

이 스레드에 쓰여진 것처럼 git ls-files는 ' --added옵션을 지원하지 않습니다 .

more fundamental reason is because ls-files plumbing is about the index.
Added is not about comparison between the index and the work tree.
It is between the HEAD commit and the index, and it does not belong to ls-files plumbing.

So, using commands mentioned here:

git diff-index --name-only -B -R -M -C HEAD src

would give you both non-added and added files

git diff-files --name-only -B -R -M -C src

would give you only non-added files. (while detecting rewrites, renames, copies, ...)

As usual with plumbing commands, some scripting is in order ;)


Imperfect, but this works as well from within the the directory you are interested in:

git status | grep -v ' \.\./'

That will hide all directories that would require an upward reference in their relative path.

If you want to get color spitting out the other end, set color.status to always:

git config color.status always

cd YOUR_REQUIRED_DIRECTORY , then,
git status .


When I tried git, I didn't find a way to do that.

I ended up doing:

x@x:~/x$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       b
#       main/a
nothing added to commit but untracked files present (use "git add" to track)

x@x:~/x$ git status | grep main
#       main/a

참고URL : https://stackoverflow.com/questions/1044446/how-to-get-git-status-of-a-single-subfolder

반응형