.gitignore에서 무시되는 특정 파일을 표시하는 Git 명령
나는 내 발이 git에 젖어 있고 다음과 같은 문제가 있습니다.
내 프로젝트 소스 트리 :
/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...
공급 업체 브랜치에 코드 (현재 MEF)가 있는데 여기에서 컴파일 한 다음 /src/refs
프로젝트가 참조 하는 곳 으로 이동합니다 .
내 문제는 내가 가지고있다 .gitignore
무시하는 설정을 *.dll
하고 *.pdb
. 나는 괜찮은 git add -f bar.dll
무시 된 파일을 강제로 추가 할 수 있습니다. 문제는 무시되는 파일을 나열 할 수 없다는 것입니다.
무시 된 파일을 나열하여 추가하는 것을 잊지 않도록하고 싶습니다.
나는 매뉴얼 페이지를 읽었고 git ls-files
그것을 작동시킬 수 없습니다. git ls-files --exclude-standard -i
내가 원하는 것을 해야하는 것 같다 . 내가 무엇을 놓치고 있습니까?
메모:
- xiaobai 의 대답은 (git1.7.6 +) 간단하다 : (에 설명 된대로 " 의 효과를 무시하는 자식-상태를 알 수있는 방법이 파일은? ")
git status --ignored
.gitignore
- MattDiPasquale 의 답변 (upvoted 예정)
git clean -ndX
은 이전 gits에서 작동하며 무시 된 파일을 제거 할 수 있는 미리보기 를 표시합니다 (아무것도 제거하지 않고)
또한 흥미 롭습니다 ( qwertymk 의 답변 에서 언급 ), git check-ignore -v
적어도 Unix에서 명령 을 사용할 수도 있습니다 ( CMD Windows 세션 에서는 작동하지 않습니다 )
git check-ignore *
git check-ignore -v *
두 번째 .gitignore
는 git repo에서 파일을 무시하도록 만드는 실제 규칙을 표시합니다 .
Unix에서 " What expands to all files in current directory recursively? "및 bash4 + 사용 :
git check-ignore **/*
(또는 find -exec
명령)
원래 답변 42009)
git ls-files -i
소스 코드 가 다음을 나타내는 것을 제외하고는 작동해야합니다 .
if (show_ignored && !exc_given) {
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
argv[0]);
exc_given
?
-i
실제로 무엇이든 나열하려면 뒤에 하나 이상의 매개 변수가 필요합니다 .
시험:
git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore
(하지만 필터와 함께 캐시 된 (무시되지 않은) 개체 만 나열 하므로 원하는 것이 아닙니다)
예:
$ cat .git/ignore
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated html files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git ls-files --ignored \
--exclude='Documentation/*.[0-9]' \
--exclude-from=.git/ignore \
--exclude-per-directory=.gitignore
실제로 내 'gitignore'파일 ( 'exclude'라고 함)에서 도움이 될 수있는 명령 줄을 찾습니다.
F:\prog\git\test\.git\info>type exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
그래서....
git ls-files --others --ignored --exclude-from=.git/info/exclude
git ls-files -o -i --exclude-from=.git/info/exclude
git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard
트릭을해야합니다.
As mentioned in the ls-files man page, --others
is the important part, in order to show you non-cached, non-committed, normally-ignored files.
--exclude_standard
is not just a shortcut, but a way to include all standard "ignored patterns" settings.
exclude-standard
Add the standard git exclusions:.git/info/exclude
,.gitignore
in each directory, and theuser's global exclusion file
.
There is a much simpler way to do it (git 1.7.6+):
git status --ignored
See Is there a way to tell git-status to ignore the effects of .gitignore files?
Another option that's pretty clean (No pun intended.):
git clean -ndX
Explanation:
$ git help clean
git-clean - Remove untracked files from the working tree
-n, --dry-run - Don't actually remove anything, just show what would be done.
-d - Remove untracked directories in addition to untracked files.
-X - Remove only files ignored by Git.
Note: This solution will not show ignored files that have already been removed.
While generally correct your solution does not work in all circumstances. Assume a repo dir like this:
# ls **/*
doc/index.html README.txt tmp/dir0/file0 tmp/file1 tmp/file2
doc:
index.html
tmp:
dir0 file1 file2
tmp/dir0:
file0
and a .gitignore like this:
# cat .gitignore
doc
tmp/*
이것은 doc
디렉토리와 아래의 모든 파일을 무시합니다 tmp
. Git은 예상대로 작동하지만 무시 된 파일을 나열하는 지정된 명령은 작동하지 않습니다. git이 무슨 말을하는지 살펴 보자 :
# git ls-files --others --ignored --exclude-standard
tmp/file1
tmp/file2
공지 사항 doc
목록에서 누락되었습니다. 다음과 같이 얻을 수 있습니다.
# git ls-files --others --ignored --exclude-standard --directory
doc/
추가 --directory
옵션을 확인하십시오.
내 지식에서 더이없는 한 번에 모든 무시 파일을 나열하는 명령. 그러나 나는 왜 tmp/dir0
전혀 나타나지 않는지 모르겠습니다 .
Git에는 이제이 기능이 내장되어 있습니다.
git check-ignore *
물론 **/*.dll
귀하의 경우 와 같이 glob을 변경할 수 있습니다.
사용하기에 충분해야합니다.
git ls-files --others -i --exclude-standard
모든 것을 다룹니다.
git ls-files --others -i --exclude-from=.git/info/exclude
따라서 후자는 중복됩니다.
~/.gitconfig
파일에 별칭을 추가하여이 작업을 더 쉽게 할 수 있습니다
.
git config --global alias.ignored "ls-files --others -i --exclude-standard"
Now you can just type git ignored
to see the list. Much easier to remember, and faster to type.
If you prefer the more succinct display of Jason Geng's solution, you can add an alias for that like this:
git config --global alias.ignored "status --ignored -s"
However the more verbose output is more useful for troubleshooting problems with your .gitignore files, as it lists every single cotton-pickin' file that is ignored. You would normally pipe the results through grep
to see if a file you expect to be ignored is in there, or if a file you don't want to be ignore is in there.
git ignored | grep some-file-that-isnt-being-ignored-properly
Then, when you just want to see a short display, it's easy enough to remember and type
git status --ignored
(The -s
can normally be left off.)
Here's how to print the complete list of files in the working tree which match patterns located anywhere in Git's multiple gitignore sources (if you're using GNU find
):
$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose
It will check all the files in the current branch of the repository (unless you've deleted them locally).
And it identifies the particular gitignore source lines, as well.
Git continues to track changes in some files which match gitignore patterns, simply because those files were added already. Usefully, the above command displays those files, too.
Negative gitignore patterns are also matched. However, these are easily distinguishable in the listing, because they begin with !
.
If you're using Windows, Git Bash includes GNU find
(as revealed by find --version
).
If the list is long (and you have rev
), you can display them by extension (somewhat), too:
$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose \
| rev | sort | rev
For more details, see man find
, man git-check-ignore
, man rev
, and man sort
.
The point of this whole approach is that Git (the software) is changing rapidly and is highly complex. By contrast, GNU's find
is extremely stable (at least, in its features used here). So, anyone who desires to be competitive by displaying their in-depth knowledge of Git will answer the question in a different way.
What's the best answer? This answer deliberately minimizes its reliance on Git knowledge, toward achieving the goal of stability and simplicity through modularity (information isolation), and is designed to last a long time.
(extending the other answers)
Note, git check-ignore
uses the committed .gitignore
and not the one in your working tree! To play with it without polluting your git history, you might freely try to edit it, and then commit with a git commit --amend
.
This problem happens mainly if you need a workaround of the problem, that git doesn't follow directories. Enter in the .gitignore
:
dirtokeep/**
!dirtokeep/.keep
.keep
should be a zero-length file in dirtokeep
.
The result will be that everything in dirtokeep
will be ignored, except dirtokeep/.keep
, which will result that also the dirtokeep
directory will be constructed on clone/checkout.
Assuming there are a few ignore directories, why not use "git status node/logs/" which will tell you what files are to be added? In the directory I have a text file that is not part of status output, e.g.:
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
node/logs/.gitignore
.gitignore is:
*
!.gitignore
'program story' 카테고리의 다른 글
고정 위치이지만 컨테이너에 상대적 (0) | 2020.10.03 |
---|---|
태그는 Git의 브랜치와 어떻게 다릅니 까? (0) | 2020.10.03 |
어느 것이 더 빠릅니까 : while (1) 또는 while (2)? (0) | 2020.10.03 |
Node.js에서 POST 데이터를 처리하는 방법은 무엇입니까? (0) | 2020.10.03 |
기본 / 내장 앱을 사용하지 않고 JavaMail API를 사용하여 Android에서 이메일 보내기 (0) | 2020.10.02 |