Sourcetree의 .gitignore 파일이 작동하지 않습니다.
나는 maven 프로젝트에서 작업 중이며 내 프로젝트 (평가) 루트 폴더의 / target 폴더에 생성되고 저장된 파일을 무시하고 싶습니다. 내 git 저장소의 루트에 다음 항목이있는 .gitignore 파일이 있습니다 (백엔드 이클립스 프로젝트 평가를 포함하는 폴더입니다)
backend/Evaluation/logs/
backend/Evaluation/target/
어떤 이유로 SourceTree는이 두 폴더에 저장된 파일을 무시하지 않으며 프로젝트를 컴파일 할 때 / target 폴더 안에 일부 .class 파일 인 커밋되지 않은 변경 사항이 있습니다.
왜 이런 일이 발생합니까? 또한 .gitignore 항목을 다음과 같이 변경하려고 시도했습니다.
/ backend / Evaluation / logs / **
그러나 그것은 너무 작동하지 않았습니다.
어떤 아이디어?
실수로 저장소에 추가 된 파일이 있다고 가정 해 보겠습니다.
stackoverflow$ echo this file is important > junkfile
stackoverflow$ git add junkfile
stackoverflow$ git ci -m 'added a file'
어느 시점에서 파일이 중요하지 않다는 것을 깨닫고 파일에 추가 .gitignore
합니다.
stackoverflow$ echo junkfile >> .gitignore
stackoverflow$ git ci -m 'ignore junkfile' .gitignore
나중에 해당 파일을 몇 가지 변경합니다.
stackoverflow$ sed -i 's/ is / is not/' junkfile
물론 파일이에 나열되어 .gitignore
있어도 이미 git에게 추적하고 싶다고 말 했으므로 다음과 같이 git status
표시됩니다.
stackoverflow$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: junkfile
#
no changes added to commit (use "git add" and/or "git commit -a")
작업 트리에서 파일을 제거하지 않고 저장소에서이 파일을 제거해야합니다. --cached
플래그를 사용하여 다음을 수행 할 수 있습니다 git rm
.
stackoverflow$ git rm --cached junkfile
rm 'junkfile'
이것은 delete
작업을 단계 ...
stackoverflow$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: junkfile
#
... 커밋해야합니다.
stackoverflow$ git commit -m 'removed junkfile from repository'
[master 19f082a] removed junkfile from repository
1 file changed, 1 deletion(-)
delete mode 100644 junkfile
이제 git status
git 을 실행 하면이 파일을 무시합니다.
stackoverflow$ git status
# On branch master
nothing to commit, working directory clean
여전히 여기 작업 트리에 있지만 :
stackoverflow$ cat junkfile
this file is not important
질문에 Sourcetree 태그가 있기 때문에 Sourcetree를 사용하여이 작업을 수행하는 방법에 대해 답변 할 것이므로 정말 간단합니다.
앞서 말했듯이 먼저 추적에서 파일을 제거한 다음 Sourcetree가 파일을 무시하도록해야합니다.
- Change something in the file so that it is shown to you or select it from the "file status" tab at the bottom of the open repository.
- Right click on the file and you see "Ignore...", but it is grayed out because as said above its already in track.
- Right click on the file and chose "Stop Tracking"
- The file will be shown with a red button which indicates it will be removed (from tracking)
- A new entry of the same file will be shown in "file status" with a blue question mark indicates a new file (new because you said remove from tracking in 4)
- Right click on the file from 5 and now you see the "Ignore..." is able to choose. Click on it and Sourcetree will put a new entry for the file in the .gitignore file
- You can see the .gitignore file if you click on "Setting" on the top right, choose "advanced" and then the first entry is about the ignore file, click on "edit" and it will be open.
I had a problem with bin folder being tracked (entire folder).
So here are the quick steps (more visual, as I'm more of a visual type of person):
- Just for security purposes, I zipped entire bin folder
- Move it to desktop
- Move (current) .gitignore to the desktop as well
- Delete entire BIN folder
- Commit changes (via favourite git commit tool)
- Commit, push, done!
- Go back to the basic project's folder
- Move back the .gitignore file
- Optional - move back (unzip) the bin folder as well.
- As a result, you will see that the git tool is no longer tracking changes from the bin folder.
I hope this helps someone.
If the files have already been added or committed to your Git repository, you must first stop tracking them before they will be ignored by .gitIgnore.
To stop tracking files in SourceTree:
Right-click on files. Choose "Stop Tracking".
(this won't delete your files, it just stops tracking them)
To stop tracking files from Command-line:
git rm --cached example.txt
In addition to the answers already provided above, also note that the .gitignore
file will not work if it is not in the root folder.
I had a project where .gitignore
was here /projectname/.gitignore
and therefore was not being read. So I moved it to /.gitignore
and all was well again.
I found that by deleting the repository, then having the .gitignore file in the folder when the repository is recreated the ignore file is respected.
This worked for me:
git update-index --assume-unchanged some.file
Struggled with this for a few hours, tried a number of things including the suggestions here - to no avail... what finally worked for me was to create the .gitignore file when setting up the repo within bitbucket.org, pulled that file to my local, pasted the exact same contents of the file I was trying to create on my own, and it is finally all working now.
참고URL : https://stackoverflow.com/questions/21616463/gitignore-file-in-sourcetree-not-working
'Development Tip' 카테고리의 다른 글
JSP에서 날짜 변환 및 형식 지정 (0) | 2020.11.25 |
---|---|
C # 생성자 오버로딩 (0) | 2020.11.25 |
초 단위로 주어진 시간 간격을 사람이 읽을 수있는 형식으로 변환 (0) | 2020.11.25 |
시간 O (n)에서 배열에서 중복 요소 찾기 (0) | 2020.11.25 |
Android ImageView : 너비 맞추기 (0) | 2020.11.25 |