Git - will file movement be detected?

I made some changes to branch (A).

Then I decided to create a completely new branch (B) based on the state of my existing working copy and commit and click on it.

There were several files that were migrated during my earlier refactoring and therefore were no longer included in version control, which were moved directly to the file system. By accident, I did not add these files to git before committing and clicking on a new branch (B).

If I add these files now and commit and click, can git detect file move operations?

+3
source share
4 answers

, , , . , git commit --amend, .

+5

, , git log:

[bd@satoko testgit] echo hello world > foo
[bd@satoko testgit] git init
gitInitialized empty Git repository in /home/bd/testgit/.git/
[bd@satoko testgit] git add foo
[bd@satoko testgit] git commit -m 'test'
[master (root-commit) 772dbe5] test
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
[bd@satoko testgit] mv foo bar
[bd@satoko testgit] echo baz > quux
[bd@satoko testgit] git add quux
[bd@satoko testgit] git commit -a -m 'rm; add'
[master 59dd10b] rm; add
 2 files changed, 1 insertions(+), 1 deletions(-)
 delete mode 100644 foo
 create mode 100644 quux
[bd@satoko testgit] git add bar
[bd@satoko testgit] git commit -m 'add'
[master 823f70f] add
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 bar

[bd@satoko testgit] git log --stat -m
commit 823f70fe50828204686a6a42a5e98dc9b258903b
Author: Bryan Donlan <bdonlan@fushizen.net>
Date:   Mon Jan 17 05:06:16 2011 -0500

    add

 bar |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

commit 59dd10bfb72bb9005edecb1b7609978d82d21652
Author: Bryan Donlan <bdonlan@fushizen.net>
Date:   Mon Jan 17 05:05:58 2011 -0500

    rm; add

 foo  |    1 -
 quux |    1 +
 2 files changed, 1 insertions(+), 1 deletions(-)

commit 772dbe5357253b533f8f2b9c64836dc09a51def4
Author: Bryan Donlan <bdonlan@fushizen.net>
Date:   Mon Jan 17 05:04:35 2011 -0500

    test

 foo |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
### As you can see, a log doesn't show the move, but...
[bd@satoko testgit] git diff --stat  823f..772d -M
 bar => foo |    0
 quux       |    1 -
 2 files changed, 0 insertions(+), 1 deletions(-)
### A direct comparison does

, git / - , / . /, , /, . git log , - "" "", .

, git rebase --interactive, , . , , .

+3

But git processes objects by content, not by paths. This means that it does not matter when you move an object (file) or delete / add an object. It will be stored only once in the git repo database.

0
source

Given that Git does not save the renaming information, but triggers some kind of rename detection mechanism, you should be fine. See Also Renaming Handling: svn vs. Git vs. mercurial

0
source

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


All Articles