2012-06-06 2 views
25

git mv를 사용하지 않고 IDE 또는 명령 행을 사용하여 git 저장소에서 파일을 이동시키는 경우가 많습니다. 결과 I로서 쉬운 방법 Git에서 삭제되지 않은 파일 정리하기

여러 unstaged 파일로 끝날

는에 삭제 될 내 옆에 다음과 같이 약속한다

# On branch master 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# modified: test.html 
# 
# Changes not staged for commit: 
# (use "git add/rm <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# deleted: css/bootstrap.css 
# deleted: css/bootstrap.min.css 
# deleted: img/glyphicons-halflings-white.png 
# deleted: img/glyphicons-halflings.png 
# deleted: js/bootstrap.js 
# deleted: js/bootstrap.min.js 
나는 일반적으로 모든 삭제 된 파일을 선택하고 같은 생산하는 텍스트 편집기에서 편집 할

:

git rm css/bootstrap.css 
git rm css/bootstrap.min.css 
git rm img/glyphicons-halflings-white.png 
git rm img/glyphicons-halflings.png 
git rm js/bootstrap.js 
git rm js/bootstrap.min.js 

다음 콘솔로 다시 던집니다.

복사/붙여 넣기를하지 않고도이 작업을 수행 할 수 있습니까? 내가 제대로 질문을 이해한다면

답변

36

, 당신은 삭제 된 것으로 표시 파일 모든에 대한 git rm의 등가을 수행하려는, 즉 ... 당신의 삭제를 커밋합니다. git clean이 작업을 수행하지 않습니다.

당신은 git add -u을 실행할 수 있습니다

만 이미 인덱스 보다는 작업 트리에서 파일을 추적에 대해 일치합니다. 즉, 새 파일 은 절대로 실행되지 않지만 추적 된 파일 의 새 내용이 단계적으로 수정되고 작업 트리의 해당 파일 이 제거되면 색인에서 파일이 제거됩니다.

이렇게하면 삭제 된 파일을 포함한 모든 변경 사항이 적용됩니다.

# Changes not staged for commit: 
# (use "git add/rm <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# deleted: file2 
# deleted: file3 
# deleted: file4 
# deleted: file5 

git add -u을 실행하면이 당신을 얻을 것이다 :

# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# deleted: file2 
# deleted: file3 
# deleted: file4 
# deleted: file5 

을 그리고 옳은 일을 할 것입니다이 시점에서 커밋 그래서이 시작합니다.

+0

는이 적합 "자식이 -A를 추가 할 것"이라고? –

0

git add -u은 추적 된 파일의 상태를 업데이트합니다.

1

나는 보통 변경 한 파일을 커밋합니다.

내가 중복 파일을 삭제 한 싶다면, 나는이 후 다음을 수행합니다 :

git commit -a -m 'deleted redundant files' 
관련 문제