Programing

git은 수정 된 변경 사항 만 추가하고 추적되지 않은 파일은 무시합니다.

lottogame 2020. 10. 3. 09:45
반응형

git은 수정 된 변경 사항 만 추가하고 추적되지 않은 파일은 무시합니다.


"git status"를 실행했고 아래에 수정 된 / 또는 "커밋을 위해 준비되지 않은 변경 사항"이라는 제목 아래에 나열된 파일이 나열되어 있습니다. 또한 무시하고 싶은 추적되지 않은 파일도 나열했습니다 (이 디렉토리에 ".gitignore"파일이 있습니다).

수정 된 파일을 스테이징에 넣어서 커밋 할 수 있도록하고 싶습니다. "git add."를 실행하면 수정 된 파일과 무시할 파일이 스테이징에 추가되었습니다.

수정 된 파일 만 추가하고 아래 git 상태가 표시되는 경우 추적되지 않은 파일을 무시하려면 어떻게해야합니까?

또한 내 ".gitignore"파일이 제대로 작동합니까?

$ git status
# On branch addLocation
# 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:   someProject/path/domain/viewer/LocationDO.java
#       modified:   someProject/path/service/ld/LdService.java
#       modified:   someProject/path/service/ld/LdServiceImpl.java
#       modified:   someProject/path/web/jsf/viewer/LocationFormAction.java
#       modified:   someProject/war/WEB-INF/classes/message/viewer/viewer.properties
#       modified:   someProject/war/page/viewer/searchForm.xhtml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .metadata/
#       someProject/build/
no changes added to commit (use "git add" and/or "git commit -a")

이상적으로 .gitignore는 추적되지 않은 (및 무시 된) 파일이 상태에 표시되거나 사용하여 추가되는 것을 방지해야합니다 git add. 따라서 수정을 요청합니다..gitignore

이렇게 git add -u하면 수정 및 삭제 된 파일이 준비됩니다.

git commit -a수정 및 삭제 된 파일 만 커밋 할 수도 있습니다.

2.0 이전 버전의 Git이 있고를 사용하는 경우을 git add .사용해야합니다 git add -u .( " " git add -A"및" git add ." "의 차이점 참조 ).


이것은 나를 위해 일했습니다.

#!/bin/bash

git add `git status | grep modified | sed 's/\(.*modified:\s*\)//'`

또는 더 나은 :

$ git ls-files --modified | xargs git add

git commit -a -m "message"

-a :이 커밋에 현재 변경 / 삭제 된 모든 파일을 포함합니다. 그러나 추적되지 않은 (새) 파일은 포함되지 않습니다.

-m : 커밋 메시지 설정


현재 귀하의은 말하지 .gitignore않았지만 .gitignore루트 디렉토리에 다음 내용이있는은 트릭을 수행해야합니다.

.metadata
build

이것이 기능인지 버그인지 확실하지 않지만 이것은 우리에게 효과적이었습니다.

git commit '' -m "Message"

Note the empty file list ''. Git interprets this to commit all modified tracked files, even if they are not staged, and ignore untracked files.


I happened to try this so I could see the list of files first:

git status | grep "modified:" | awk '{print "git add  " $2}' > file.sh

cat ./file.sh

execute:

chmod a+x file.sh
./file.sh 

Edit: (see comments) This could be achieved in one step:

git status | grep modified | awk '{print $2}' | xargs git add && git status

참고URL : https://stackoverflow.com/questions/7124726/git-add-only-modified-changes-and-ignore-untracked-files

반응형