How to make git mark a deleted and a new file as a file move ?

How to make git mark a deleted and a new file as a file move ?

Asked on January 7, 2019 in Git.
Add Comment


  • 4 Answer(s)

    Git will necessarily detect the move/rename if your reduction. Just git add the new file, and git rm the advanced file. git status will display either it has detected the rename.

    furthermore, for moves around directories,

    1.  cd to the top of that directory structure.
    2. Run git add -A .
    3. Run git status to verify that the “new file” is now a “renamed” file

    If git status still display “new file” and not “renamed” and modify in two separate commits.

    Answered on January 7, 2019.
    Add Comment

    Move and change the separate commits.

    Answered on January 7, 2019.
    Add Comment

    All a affective thing. Git is generally rather good at recognising moves, because GIT is a content tracker

    All that really depends is how your “stat” show it. Only difference here is the -M flag.

    git log –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(-)
    

     

    git log –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(-)
    

    git help log

    -M
    Detect renames.
    -C
    Detect copies as well as renames. See also --find-copies-harder.
    
    Answered on January 7, 2019.
    Add Comment

    Git will automatically detect the move/rename if your modification is not too severe. Just git add the new file, and git rm the old file. git status will then show whether it has detected the rename.

    additionally, for moves around directories, you may need to:

    1. cd to the top of that directory structure.
    2. Run git add -A .
    3. Run git status to verify that the “new file” is now a “renamed” file
    Answered on March 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.