파일을 수동으로 옮긴 다음 수정했습니다. Git에 따르면 새 파일이고 제거 된 파일입니다. Git을 파일 이동으로 처리하도록 강제 할 수있는 방법이 있습니까?
답변
수정이 너무 심각하지 않은 경우 Git은 자동으로 이동 / 이름 바꾸기를 감지합니다. 그냥 git add
새 파일과 git rm
이전 파일.git status
그러면 이름 변경을 감지했는지 여부가 표시됩니다.
또한 디렉토리를 이동하려면 다음이 필요합니다.
- 해당 디렉토리 구조의 맨 위에 cd.
- 운영
git add -A .
git status
“새 파일”이 이제 “이름이 바뀐”파일인지 확인하기 위해 실행
자식 상태가 여전히 “이름 바꾸기”가 아닌 “새 파일”로 표시되면 행크 게이의 조언 을 따르고 두 가지 커밋으로 이동하고 수정해야합니다.
답변
별도의 커밋으로 이동 및 수정을 수행하십시오.
답변
그것은 모두 지각적인 것입니다. GIT는 일반적으로 동작 인식에 다소 능숙합니다. GIT 는 콘텐츠 추적기
실제로 의존하는 것은 “통계”가 표시하는 방법입니다. 여기서 유일한 차이점은 -M 플래그입니다.
자식 로그 –stat -M
commit 9c034a76d394352134ee2f4ede8a209ebec96288
Author: Kent Fredric
Date: Fri Jan 9 22:13:51 2009 +1300
Category Restructure
lib/Gentoo/Repository.pm | 10 +++++-----
lib/Gentoo/{ => Repository}/Base.pm | 2 +-
lib/Gentoo/{ => Repository}/Category.pm | 12 ++++++------
lib/Gentoo/{ => Repository}/Package.pm | 10 +++++-----
lib/Gentoo/{ => Repository}/Types.pm | 10 +++++-----
5 files changed, 22 insertions(+), 22 deletions(-)
자식 로그 –stat
commit 9c034a76d394352134ee2f4ede8a209ebec96288
Author: Kent Fredric
Date: Fri Jan 9 22:13:51 2009 +1300
Category Restructure
lib/Gentoo/Base.pm | 36 ------------------------
lib/Gentoo/Category.pm | 51 ----------------------------------
lib/Gentoo/Package.pm | 41 ---------------------------
lib/Gentoo/Repository.pm | 10 +++---
lib/Gentoo/Repository/Base.pm | 36 ++++++++++++++++++++++++
lib/Gentoo/Repository/Category.pm | 51 ++++++++++++++++++++++++++++++++++
lib/Gentoo/Repository/Package.pm | 41 +++++++++++++++++++++++++++
lib/Gentoo/Repository/Types.pm | 55 +++++++++++++++++++++++++++++++++++++
lib/Gentoo/Types.pm | 55 -------------------------------------
9 files changed, 188 insertions(+), 188 deletions(-)
자식 도움말 로그
-M
Detect renames.
-C
Detect copies as well as renames. See also --find-copies-harder.
답변
git diff -M
또는 사소한 변경이git log -M
있는 한 이름 변경과 같은 변경 사항을 자동으로 감지해야합니다 . 귀하의 경우 사소한 변경 사소한되지 않습니다, 당신은 유사성 threashold을 줄일 수 있습니다, 예를 들어,
$ git log -M20 -p --stat
기본 50 %에서 20 %로 줄입니다.
답변
다음은 커밋되지 않은 하나 또는 몇 개의 이름이 바뀌고 수정 된 파일에 대한 빠르고 더러운 솔루션입니다.
파일 이름이 지정 foo
되었고 이제 이름이 지정되었다고 가정 해 봅시다 bar
.
-
bar
임시 이름으로 이름 을 바꿉니다 .mv bar side
-
체크 아웃
foo
:git checkout HEAD foo
-
힘내로 이름
foo
을 바꾸십시오bar
:git mv foo bar
-
이제 임시 파일 이름을 다시로 바꿉니다
bar
.mv side bar
마지막 단계는 변경된 내용을 파일로 다시 가져 오는 것입니다.
이것이 작동 할 수는 있지만, 이동 된 파일이 원래 자식과 내용이 너무 다르면 이것이 새로운 객체인지 결정하는 것이 더 효율적이라고 생각할 것입니다. 보여 드리겠습니다 :
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
renamed: README -> README.md
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: README.md
modified: work.js
$ git add README.md work.js # why are the changes unstaged, let's add them.
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
deleted: README
new file: README.md
modified: work.js
$ git stash # what? let's go back a bit
Saved working directory and index state WIP on dir: f7a8685 update
HEAD is now at f7a8685 update
$ git status
On branch workit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
nothing added to commit but untracked files present (use "git add" to track)
$ git stash pop
Removing README
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
new file: README.md
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: README
modified: work.js
Dropped refs/stash@{0} (1ebca3b02e454a400b9fb834ed473c912a00cd2f)
$ git add work.js
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
new file: README.md
modified: work.js
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: README
$ git add README # hang on, I want it removed
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
deleted: README
new file: README.md
modified: work.js
$ mv README.md Rmd # Still? Try the answer I found.
$ git checkout README
error: pathspec 'README' did not match any file(s) known to git.
$ git checkout HEAD README # Ok the answer needed fixing.
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
new file: README.md
modified: work.js
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: README.md
modified: work.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
Rmd
$ git mv README README.md
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
renamed: README -> README.md
modified: work.js
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: work.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
Rmd
$ mv Rmd README.md
$ git status
On branch workit
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
renamed: README -> README.md
modified: work.js
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: README.md
modified: work.js
$ # actually that's half of what I wanted; \
# and the js being modified twice? Git prefers it in this case.
답변
git status
이름 변경을 표시하지 않는 것에 대해 이야기하는 경우 git commit --dry-run -a
대신 시도하십시오.
답변
TortoiseGit을 사용하는 경우 Git의 자동 이름 변경 감지는 커밋 중에 발생하지만이 사실이 항상 소프트웨어에 의해 항상 표시되는 것은 아닙니다. 두 파일을 다른 디렉토리로 옮기고 약간의 편집 작업을 수행했습니다. TortoiseGit을 커밋 도구로 사용하고 Changes made (변경된 항목) 목록에 이동하지 않고 삭제 및 추가 된 파일이 표시되었습니다. 커맨드 라인에서 git status를 실행하면 비슷한 상황이 나타납니다. 그러나 파일을 커밋 한 후 로그에서 이름이 바뀐 것으로 나타납니다. 따라서 귀하의 질문에 대한 답변은 너무 과감한 일을하지 않은 한 Git은 자동으로 이름 바꾸기를 선택해야합니다.
편집 : 분명히 새 파일을 추가 한 다음 명령 줄에서 git 상태를 수행하면 커밋 전에 이름 바꾸기가 표시되어야합니다.
편집 2 : 또한 TortoiseGit에서 커밋 대화 상자에 새 파일을 추가하지만 커밋하지 마십시오. 그런 다음 Show Log 명령으로 이동하여 작업 디렉토리를 보면 Git이 커밋하기 전에 이름 바꾸기를 감지했는지 확인할 수 있습니다.
동일한 질문이 여기에 제기되었습니다 : https://tortoisegit.org/issue/1389 여기 에서 해결하기위한 버그로 기록되었습니다 : https://tortoisegit.org/issue/1440 TortoiseGit의 커밋과 관련된 디스플레이 문제입니다 새 파일을 추가하지 않은 경우 대화 상자 및 일종의 자식 상태가 존재합니다.