Programing

.gitignore가 추적되지 않는 파일 목록에 나타나지 않도록하려면 어떻게해야합니까?

crosscheck 2020. 9. 28. 08:16
반응형

.gitignore가 추적되지 않는 파일 목록에 나타나지 않도록하려면 어떻게해야합니까?


git init새 프로젝트의 루트에서 방금 작업했습니다.

그런 다음 .gitignore파일을 만들었습니다 .

이제를 입력 git status하면 .gitignore 파일이 추적되지 않은 파일 목록에 나타납니다. 왜 그런 겁니까?


.gitignore로 실제로, 추가에 최선을 다하고해야하므로 파일 저장소에 있어야 git status제안한다. 변경 사항을 병합하는 등의 작업을 수행하려면 저장소 트리의 일부 여야합니다.

따라서 저장소에 추가하십시오. gitignored해서는 안됩니다.

당신은 정말 당신이 추가 할 수 있습니다 원하는 경우 .gitignore받는 .gitignore파일 당신은 최선을 다하고하지 않으려면. 그러나이 경우에는 .git/info/exclude.gitignore처럼 작동하지만 .git폴더 에 있으므로 "git status"에 표시되지 않는 특수한 checkout-local 파일 인에 ignores 를 추가하는 것이 좋습니다 .

참조 https://help.github.com/articles/ignoring-files


Git 트리 외부에 무시 된 파일 목록을 저장하려면 .git / info / exclude 파일을 사용할 수 있습니다 . 저장소 체크 아웃에만 적용됩니다.


실제로 ".gitignore"파일에 ".gitignore"줄을 넣을 수 있습니다. 이로 인해 ".gitignore"파일이 git에 의해 무시됩니다. 나는 이것이 좋은 생각이라고 생각하지 않는다. 무시 파일은 버전을 제어하고 추적해야한다고 생각합니다. 나는 완성을 위해 이것을 거기에 넣는 것입니다.


모든 저장소에 .gitignore자동으로 적용 되는 전역 사용자 git 파일을 가질 수도 있습니다 . 이것은 IDE 및 편집기 파일 (예를 들어, 유용합니다 빔에 대한 파일). OS에 맞게 디렉토리 위치 변경swp*~

  1. ~/.gitconfig파일에 추가

    [core]
    excludesfile = /home/username/.gitignore
    
  2. ~/.gitignore무시할 파일 패턴이 있는 파일 만들기

  3. 백업 할 수 있도록 도트 파일을 다른 저장소에 저장합니다 (선택 사항).

repo를 복사, 초기화 또는 복제 할 때마다 전역 gitignore 파일도 사용됩니다.


누군가 이미 .gitignore리포지토리에을 추가 했지만 일부를 변경하고 해당 변경 사항을 무시하려면 다음을 수행하십시오.

git update-index --assume-unchanged .gitignore

소스 .


.gitignore파일 을 추가 하고 커밋하면 더 이상 "추적되지 않은 파일"목록에 표시되지 않습니다.

git add .gitignore
git commit -m "add .gitignore file"
git status

다른 사람이 우리와 똑같은 고통을 겪을 수도 있습니다. 이미 커밋 된 파일을 제외하고 싶었습니다.

이 게시물은 훨씬 더 유용했습니다. .git / info / exclude 작업이 너무 늦었습니다.

특히 파일을 무시해야하는 것은 실제로 git remove 명령을 사용하는 것입니다. git rm 참조 ( http://www.kernel.org/pub/software/scm/git/docs/git-rm.html )

당신은 가서 그것을 테스트

git rm --dry-run *.log
(모든 로그 파일을 제외하려는 경우)

어떤이가 출력 될 것입니다 당신이 그것을 실행 한 경우 제외.

그때

당신은 가서 그것을 실행

git rm *.log
(또는 원하는 파일 이름 경로 / 표현식)

그런 다음 파일에 *.log행을 추가 .gitignore하십시오.


물론 .gitignore 파일은 추적되지 않았기 때문에 상태에 표시되고 git은이를 맛있는 새 파일로 간주합니다!

그러나 .gitignore는 추적되지 않는 파일이기 때문에 .gitignore에 넣을 때 git에서 무시할 수있는 후보입니다!

따라서 답은 간단합니다. 다음 줄을 추가하면됩니다.

.gitignore # Ignore the hand that feeds!

.gitignore 파일에!

그리고 August의 응답과는 반대로 .gitignore 파일 저장소에 있어야한다는 것이 아닙니다 . 그것은 종종 편리 할 수 있습니다. 그리고 이것이 저장소에서 추적 할 수있는 옵션이없는 .git / info / exclude의 대안으로 .gitignore가 만들어진 이유라는 것은 사실 일 것입니다. 어쨌든 .gitignore 파일을 사용하는 방법은 전적으로 귀하에게 달려 있습니다.

참고 로 kernel.org gitignore (5) 맨 페이지확인하십시오 .


아이디어는 프로젝트에 특정한 파일을 파일에 넣고 .gitignore(이미 언급했듯이) 저장소에 추가하는 것입니다. 예를 들어 .pyc.o파일, 일부 비품 등이있는 TestSuite가 생성하는 로그

For files that your own setup creates but which will not necessarily appear for every user (like .swp files if you use vim, hidden ecplise directories and the like), you should use .git/info/exclude (as already mentioned).


First of all, as many others already said, your .gitignore should be tracked by Git (and should therefore not be ignored). Let me explain why.

(TL;DR: commit the .gitignore file, and use a global .gitignore to ignore files that are created by your IDE or operating system)

Git is, as you probably already know, a distributed version control system. This means that it allows you to switch back and forth between different versions (even if development has diverged into different branches) and it also allows multiple developers to work on the same project.

Although tracking your .gitignore also has benefits when you switch between snapshots, the most important reason for committing it is that you'll want to share the file with other developers who are working on the same project. By committing the file into Git, other contributers will automatically get the .gitignore file when they clone the repository, so they won't have to worry about accidentally committing a file that shouldn't be committed (such as log files, cache directories, database credentials, etc.). And if at some point the project's .gitignore is updated, they can simply pull in those changes instead of having to edit the file manually.

Of course, there will be some files and folders that you'll want to ignore, but that are specific for you, and don't apply to other developers. However, those should not be in the project's .gitignore. There are two other places where you can ignore files and folders:

  • Files and folders that are created by your operating system or IDE should be placed in a global .gitignore. The benefit is that this .gitignore is applied to all repositories on your computer, so you don't have to repeat this for every repository. And it's not shared with other developers, since they might be using a different operating system and/or IDE.
  • Files that don't belong in the project's .gitignore, nor in the global .gitignore, can be ignored using explicit repository excludes in your_project_directory/.git/info/exclude. This file will not be shared with other developers, and is specific for that single repository

Watch out for the following "problem" Sometimes you want to add directories but no files within those directories. The simple solution is to create a .gitignore with the following content:

*

This seams to work fine until you realize that the directory was not added (as expected to your repository. The reason for that is that the .gitignore will also be ignored, and thereby the directory is empty. Thus, you should do something like this:

*
!.gitignore

This seems to only work for your current directory to get Git to ignore all files from the repository.

update this file

.git/info/exclude 

with your wild card or filename

*pyc
*swp
*~

In my case, I want to exclude an existing file. Only modifying .gitignore not work. I followed these steps:

git rm --cached dirToFile/file.php
vim .gitignore
git commit -a

In this way, I cleaned from cache the file that I wanted to exclude and after I added it to .gitignore.


If you've already checked in .gitignore and you want to ignore modifications to it, check out this answer:

Try using this command:

git update-index --assume-unchanged FILENAME_TO_IGNORE

To reverse it (if you ever want to commit changes to it), use:

git update-index --no-assume-unchanged

UPDATE:

Here's how to list 'assume unchanged' files under current directory:

git ls-files -v | grep -E "^[a-z]"

As the -v option will use lowercase letters for 'assume unchanged' files.


Navigate to the base directory of your git repo and execute the following command:

echo '\\.*' >> .gitignore

All dot files will be ignored, including that pesky .DS_Store if you're on a mac.


It is quite possible that an end user wants to have Git ignore the ".gitignore" file simply because the IDE specific folders created by Eclipse are probably not the same as NetBeans or another IDE. So to keep the source code IDE antagonistic it makes life easy to have a custom git ignore that isn't shared with the entire team as individual developers might be using different IDE's.


.gitignore is about ignoring other files. git is about files so this is about ignoring files. However as git works off files this file needs to be there as the mechanism to list the other file names.

If it were called .the_list_of_ignored_files it might be a little more obvious.

An analogy is a list of to-do items that you do NOT want to do. Unless you list them somewhere is some sort of 'to-do' list you won't know about them.


I think that there are situations where ignoring the .gitignore is very useful. For instance, when you have multiple teams or a large team working on the same codebase. In that case, you need to have certain conventions, one of those convention is regarding what is ignored at the git repo. It is usually about ignoring files and directories created by IDE or OS, some generated logs, etc.

However, there is a force which is tending to introduce non-conventional changes to .gitignore file. The .gitignore file can be further changed by irresponsible person, by mistake, by a tool that is used, or in some other case.

To have a counter force to this, we can do as followed:

  1. The initial .gitignore should reflect convention in team(s),
  2. After it is pushed, the .gitignore should be secured by adding .gitignore entry and push that change again.The .gitignore file is "sealed" in this way.

The "sealed" .gitignore file can be changed, just locally, without propagating that changers to other members of team(s). However, if a change is widely agreed throughout the whole team(s) than it is possible to "unseal" it, change it and than "seal" it again. That can't be done by mistake, only intentionally.

Sadly, you cannot be 100% protected from the stupidity, but this way you have done everything you can to prevent stupid things to happen.

If you have relatively small team with very good professionals, than this wouldn't be important, but even those guys would appreciate to have one thing less to worry about.

Using .git/info/exclude is cool when you cannot do anything about infrastructure settings, just covering your own a** not to make a mistake.

From a standing point of what is right and what is wrong I am voting for having .gitignore entry inside .gitignore file, giving everybody the freedom to do locally whatever they want, but not invading others.


I found that the best place to set up an ignore to the pesky .DS_Store files is in the .git/info/exclude file.

IntelliJ seems to do this automatically when you set up a git repository in it.

참고URL : https://stackoverflow.com/questions/767147/how-can-i-stop-gitignore-from-appearing-in-the-list-of-untracked-files

반응형