2024-07-19 Git ignore

이재성·2024년 7월 19일
post-thumbnail

git ignor란

Git 저장소에서 추적하지 않을 파일이나 디렉토리를 지정하는 설정 파일입니다. Git은 파일 변경 내역을 추적하고 버전을 관리하는데, 때때로 특정 파일이나 디렉토리는 버전 관리에서 제외하고 싶을 때 이용하여 Git이 이 파일들을 무시하도록 설정하게 하는 파일입니다.

왜 사용할까?

Gitignore 파일을 추가하면 Git은 해당 패턴에 맞는 파일이나 디렉토리의 변경 사항을 추적하지 않고, 버전 관리에서 제외합니다. 이는 프로젝트를 깨끗하게 유지하고, 필요 없는 파일이나 개인 정보가 노출되는 것을 방지하는 데 도움을 준다.

작성법

각 프로젝트의 요구에 맞게 적절히 작성되어야 하며, 주석은 # 기호로 시작하여 추가

예시) gitignore.io

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

오류

처음 하다보면 적용이 안된 것 처럼 커밋에 안떠야 되는 파일들이 계속 커밋하라고 나오게된다..
그 이유는 처음 생성되었을때 설정을 지니고 있는 git 캐시가 원인 이다.

해결

git에 있는 캐시 파일을 다 지우고 커밋을 진행하면 대부분이 해결된다.

git rm -r --cached .
git add .
git commit -m "removed cached"

이렇게 오늘 프로젝트 레포를 팠을 때 왜 이그노어가 작동하지 않았는지 알 수 있었고
다음에는 이런 오류가 나와도 당황하지 않을 것 같다.

profile
하이요

0개의 댓글