본문 바로가기
프로그래밍/Git

.gitignore 파일 설정과 .idea파일 제거 - Git rm -cached

by Mr-후 2023. 1. 5.
반응형

프로젝트를 checkout받고 IntelliJ에 open 하고 디버깅 실행을 하려고 하니 Gradle 버전 관련 설정을 맞추라고 오류가 뜬다. 
뭔 말일까하고 한참을 들여다보고 설정을 하고 나서 제대로 서버가 구동이 되었다. 
소스트리상에 커밋되지 않은 2개의 파일이 나타났는데. 

.idea/gradle.xml
.idea/modules.xml 

.gitignore가 잘못 설정되어 초기에 push가 된 것 같다. 

.idea폴더는 사용자별 빌드 환경이 서로 다를 수 있어서 제외시켜서 초기 git설정을 했어야 했지만 그렇지 않은 듯했다. 

나 역시 처음에는 개념을 이해하지 못해,
해당 파일을 delete시키고,
레파지토리를 다시 체크아웃하고
.gitignore에 해당 폴더(.idea)에 대한 설정을 추가하고
커밋한 다음 프로젝트를 다시 열었다.
그리고 빌드를 하면 또 커밋되지 않은 파일이 있다고 나온다.

왜 이런거지? 라는 의구심으로 시작해 해결책을 찾기 시작했다. 

이유는 위에 있는 것처럼 처음 .gitignore설정파일을 추가할 때 해당 폴더에 대한 설정을 추가하고 Git을 초기화 했다면 괜찮아겠지만 그렇지 않았기 때문이다. 서로 다른 idea환경이 처음 셋팅한 사람꺼로 올라가 있기 때문에 서로 다르다고 나오는 것이다. (windows, mac, linux 등, gradle버전 등..) 

이 문제를 해결하기위해서 원격 저장소에 있는 .idea파일을 지우고 커밋을 하고 푸시하면 해결이 된다. 

해당 프로젝트 폴더에서 다음 명령어를 수행한다. 

% git rm --cached -r .idea/

rm '.idea/aws.xml'
rm '.idea/gradle.xml'
rm '.idea/modules.xml'

git rm --caches [파일 이름] -> 원격 저장소에 있는 파일을 삭제한다. 로컬 저장소에 있는 파일은 삭제하지 않는다. 

위와 비슷한 명령어로  git rm [파일 이름] ->  원격 저장소와 로컬 저장소에 있는 파일을 모두 삭제한다. 

 

이렇게 하고 commit 후, push한 다음, 다른 사람에게 pull받아 테스트를 하게 하고, 나 역시 재 빌드를 하였더니 소스트리에는 아무 변화가 없었고, 잘 빌드 후 실행 되었다. 

IntelliJ 제조사에서 프로젝트 .gitignore에 대해 정리한 내용이 있다. 다음 URL에서 확인 가능하다. 

https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore

 

GitHub - github/gitignore: A collection of useful .gitignore templates

A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.

github.com

 

# 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

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

프로젝트 성격에 맞게 Git 초기화시에 조금 더 신경써서 한다면 개발 환경 구축이 좀 더 깔끔하게 될 것 같다. 

 

반응형

'프로그래밍 > Git' 카테고리의 다른 글

Git 불필요한 파일들은 Commit 제외 시키기  (0) 2018.09.10