git repo에서 파일 이름 변경
git은 파일 이름 변경을 어떻게 처리합니까?
파일 이름 변경이 수정으로 감지 git add
됩니까? 아니면 제거해야하는 "손실"파일이 있습니까? 그런 다음 새 파일을 추가해야 합니까?
수정 된 것으로 자동 감지되고 "새"파일이 색인에 추가되므로 하나의 명령 만 필요합니다.
$ git mv application.py newApplication.py
$ git status
# On branch buildServer
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: application.py -> newApplication.py
그리고 물론 커밋 ..
각 커밋에서 git은 해당 상태를 생성 한 이름이 변경되었는지 여부가 아닌 소스 트리의 상태를 기록합니다. 따라서 일반적으로 파일 이름을 바꾸면 (를 사용하지 않고 git mv
)의 출력은 git status
다음과 같습니다.
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: foo.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bar.txt
no changes added to commit (use "git add" and/or "git commit -a")
그런 다음 해당 파일의 이름을 변경하여 트리의 상태를 기록하기로 결정한 경우 다음을 사용하여 해당 변경 사항을 준비 할 수 있습니다.
git rm foo.txt
git add bar.txt
... 그러면 다음 git status
이 표시됩니다.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: foo.txt -> bar.txt
... 그리고 git commit
평소 와 같이 커밋 할 수 있습니다 .
git commit -m "Renamed foo.txt to bar.txt"
중요한 점은 git이 히스토리를 볼 때 파일의 이름이 바뀌 었다고 알려줄 때 한 버전에서 다른 버전으로 트리의 상태를 비교하여 이름이 바뀌 었음이 확인 되었기 때문입니다. 이름 변경 작업이 기록에 기록되었음을 의미 하지는 않습니다 .
이전 답변에서 설명했듯이 Git은 소스 트리의 내용 변경에서 파일 이름 바꾸기 작업을 파생시킵니다. 이름 바꾸기 작업을 기록하기 위해 Git은 이름 바꾸기 작업 자체가 아니라 삭제 및 추가 작업을 모두 저장합니다.
으로 매그너스 스코그는 지적 git mv <filename1> <filename2>
에 내용을 추가 망할 놈의 지시 <filename1>
에 <filename2>
제거 <filename1>
파일 트리에서.
으로 마크 Longair는 설명 대신하는 경우 git mv
, 당신은 쉘 명령을 사용 mv <filename1> <filename2>
하면 호출 할 때까지 힘내 이름 바꾸기 작업을 검색하지 않습니다 git rm <filename1>
및 git add <filename2>
.
그러나 이름 바꾸기 작업에 대해 Git에 알리는 또 다른 방법 mv
은 git add --all
. 이 명령은 Git이 이름을 변경 한 파일을 포함하여 저장소의 파일과 다른 작업 공간의 모든 파일을 감지하고 커밋 할 준비를하도록 지시합니다.
$ ls
a b c d
$ mv d e
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: d
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# e
no changes added to commit (use "git add" and/or "git commit -a")
$ git add --all
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: d -> e
#
git add --all
예를 들어 스크립트 또는 대량 이름 변경 도구를 사용하여 작업 영역에서 이름을 바꾼 많은 수의 파일을 커밋하는 매우 편리한 방법입니다.
git mv
이것은 기록을 유지하고 파일을 이동합니다. 나중에 커밋을 수행해야 저장소가 최신 상태가됩니다.
Git will also pick up files that are moved in the filesystem on commit (some times) and on occasions comes up with a false positive when a file is deleted and a new (but similar) file is created.
It will also move the file in the filesystem (this can be overridden). So no need to do an git add
'git mv old_file_name new_file_name'
will do the necessary modification, by default it will rename the older file name with newer file name as shown below,
rkalaiselvan@CHN-LAP-RAVICHA MINGW64 ~/Documents/GitHub/project-euler-solutions/python (development)
$ git status
On branch development
Your branch is up to date with 'origin/development'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
problem_2.py
nothing added to commit but untracked files present (use "git add" to track)
rkalaiselvan@CHN-LAP-RAVICHA MINGW64 ~/Documents/GitHub/project-euler-solutions/python (development)
$ git mv problem_1.py multiples_of_3_and_5.py
rkalaiselvan@CHN-LAP-RAVICHA MINGW64 ~/Documents/GitHub/project-euler-solutions/python (development)
$ git status
On branch development
Your branch is up to date with 'origin/development'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: problem_1.py -> multiples_of_3_and_5.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
problem_2.py
참고URL : https://stackoverflow.com/questions/5551556/changing-file-names-in-git-repo
'Program Tip' 카테고리의 다른 글
부동 소수점 나누기 대 부동 소수점 곱하기 (0) | 2020.11.14 |
---|---|
언제 Sql Azure를 사용해야하고 언제 Table Storage를 사용해야합니까? (0) | 2020.11.14 |
타임 스탬프 (자동)는 언제 업데이트됩니까? (0) | 2020.11.14 |
Cloudfront는 SSL을 사용하여 www를 네이 키드 도메인으로 리디렉션합니다. (0) | 2020.11.14 |
apk 파일을 설치하는 동안 "패키지가 손상된 것 같습니다"오류가 발생합니다. (0) | 2020.11.14 |