How to tell Git that it's the same directory, just a different name

后端 未结 5 1188
暗喜
暗喜 2020-12-03 07:08

After getting past a few hurdles learning Git, I came across a new challenge: Renaming a directory (locally, in the working directory).

When I type git status<

5条回答
  •  失恋的感觉
    2020-12-03 07:22

    Git 2.18 (Q2 2018) should to detect "that it's the same directory, just a different name", because "git status" learned to pay attention to UI related diff configuration variables such as diff.renames.

    See commit dc6b1d9 (04 May 2018) by Eckhard S. Maaß (``).
    (Merged by Junio C Hamano -- gitster -- in commit 1e174fd, 23 May 2018)

    wt-status: use settings from git_diff_ui_config

    If you do something like:

    - git add .
    - git status
    - git commit
    - git show (or git diff HEAD)
    

    one would expect to have analogous output from git status and git show (or similar diff-related programs).
    This is generally not the case, as git status has hard coded values for diff related options.

    With this commit the hard coded settings are dropped from the status command in favour for values provided by git_diff_ui_config.

    What follows are some remarks on the concrete options which were hard coded in git status:

    `diffopt.detect_rename`
    

    Since the very beginning of git status in a3e870f ("Add "commit" helper script", 2005-05-30, Git v0.99), git status always used rename detection, whereas with commands like show and log one had to activate it with a command line option.
    After 5404c11 ("diff: activate diff.renames by default", 2016-02-25, Git v2.9.0) the default behaves the same by coincidence, but changing diff.renames to other values can break the consistency between git status and other commands again.
    With this commit one control the same default behaviour with diff.renames.

    `diffopt.rename_limit`
    

    Similarly one has the option diff.renamelimit to adjust this limit for all commands but git status. With this commit git status will also honor those.


    And the same Git 2.18 offer status.renames, which could be useful for those who want to do so without disabling the default rename detection done by the "git diff" command.

    See commit e8b2dc2 (11 May 2018) by Ben Peart (benpeart).
    (Merged by Junio C Hamano -- gitster -- in commit 5da4847, 30 May 2018)

    add status config and command line options for rename detection

    After performing a merge that has conflicts git status will, by default, attempt to detect renames which causes many objects to be examined.
    In a virtualized repo, those objects do not exist locally so the rename logic triggers them to be fetched from the server. This results in the status call taking hours to complete on very large repos vs seconds with this patch.

    Add a new config status.renames setting to enable turning off rename detection during status and commit.
    This setting will default to the value of diff.renames.

    Add a new config status.renamelimit setting to to enable bounding the time spent finding out inexact renames during status and commit.
    This setting will default to the value of diff.renamelimit.

    Add --no-renames command line option to status that enables overriding the config setting from the command line.
    Add --find-renames[=] command line option to status that enables detecting renames and optionally setting the similarity index.

提交回复
热议问题