Git copy file, unlike `git mv`

I understand that git works by distinguishing between the contents of files. I have files that I want to copy. To completely prevent git confusion, is there some kind of git command that can be used to copy files to another directory (not mv, but cp), and also generate files?

+4
source share
1 answer

The short answer is simply no. But there is still to know; it just requires some background. (And as JDB suggests in a comment , I will explain why it git mvexists as a convenience.)

A little longer: you are correct that Git will have diff files, but you may be mistaken when Git performs these file changes.

Git , . , , .. , , git commit. 1

, blob Git. blob , : , , blob. , , 100 , , 99 , . 2

, , Git diff , . , - (, , , , git commit).

blob . Git "" .pack. - , Git blob ( ) - , . -, , , , . , ( !) , , .

, Git ? : . " " - git diff, :

git diff commit1 commit2

:

git show commit  # roughly, `git diff commit^@ commmit`
git log -p       # runs `git show commit`, more or less, on each commit

, , git show , Git , git log -p diffs -, , , Git git diff.

Git git diff, () . -C, --find-copies=<number>, Git . --find-copies-harder ( Git " " ) , -C. -B ( ) -C. -M aka --find-renames=<number> -C. git merge , , , , , .

( , git blame, , ).


1 git commit --include <paths> git commit --only <paths> git commit <paths> git commit -a, git commit. --only, Git , , - , . , Git HEAD, , --only. Git , .

2 , , blob , git add. git commit , , git add, git commit.


git mv

git mv old new, :

mv old new
git add new
git add old

: . : . , , : "" , ? , git add : , .

:

git rm --cached old

, , - .

, " ". , git commit. . , HEAD, HEAD .

, :

echo I am a foo > foo
git add foo

foo . . :

echo I am a bar > foo

. , foo bar, - 3 - . :

mv foo bar
git add bar

I am a bar . foo, I am a foo.

, git mv foo bar -, move-add-and-remove. . , - .

, git mv. 4 , git add , . , , git cp , , , , . git cp . git mv --after, a la Mercurial hg mv --after. , . ( , , , , git mv.)


3 . git add -p , , , , , - .

4 : git ls-index --stage , , git update-index . , -, git mv --after git cp.

+7

Source: https://habr.com/ru/post/1689594/


All Articles