代码之家  ›  专栏  ›  技术社区  ›  BoarGules

一行代码的变化由德威治上演显示每行不同

  •  1
  • BoarGules  · 技术社区  · 6 年前

    git status 报告

    S:\mydir\AEL>git status CodingTools_SourceControl.ael
    On branch master
    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:   CodingTools_SourceControl.ael
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    这是改变 diff

    S:\mydir\AEL>git diff CodingTools_SourceControl.ael
    diff --git a/AEL/CodingTools_SourceControl.ael b/AEL/CodingTools_SourceControl.ael
    index 7ae86d7..fd53caa 100644
    --- a/AEL/CodingTools_SourceControl.ael
    +++ b/AEL/CodingTools_SourceControl.ael
    @@ -22,7 +22,7 @@ import ael
     import acm
     is_64_bit = True
    
    -# Special-purpose overrides
    +# Special-purpose overrides. These deliberately require minor code changes.
     #CodingTools_PyLint.VERBOSE = True
     #CodingTools_PyLint.PYLINTRC = "default.pylintrc"
    

    现在我准备改变:

    S:\mydir\AEL>git add CodingTools_SourceControl.ael
    
    S:\mydir\AEL>git status CodingTools_SourceControl.ael
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   CodingTools_SourceControl.ael
    

    如果我要一份关于阶段性变化的报告,我会看到同样的一行变化:

    S:\mydir\AEL>git diff --cached CodingTools_SourceControl.ael
    diff --git a/AEL/CodingTools_SourceControl.ael b/AEL/CodingTools_SourceControl.ael
    index 7ae86d7..fd53caa 100644
    --- a/AEL/CodingTools_SourceControl.ael
    +++ b/AEL/CodingTools_SourceControl.ael
    @@ -22,7 +22,7 @@ import ael
     import acm
     is_64_bit = True
    
    -# Special-purpose overrides
    +# Special-purpose overrides. These deliberately require minor code changes.
     #CodingTools_PyLint.VERBOSE = True
     #CodingTools_PyLint.PYLINTRC = "default.pylintrc"
    

    现在我解开零钱

    S:\PrimeObjects\ADSO71\KEATING\AEL>git reset CodingTools_SourceControl.ael
    Unstaged changes after reset:
    M       AEL/ATS_SourceControl.ael
    ...several other unstaged changes...
    

    我希望能够使用德威治来管理登台和提交。所以内部闲置,之后 reset ,我这样做:

    >>> from dulwich.repo import Repo
    >>> repo = Repo(br"S:\mydir")
    >>> repo.stage([br"AEL\CodingTools_SourceControl.ael"])
    

    git状态

    S:\mydir\AEL>git status CodingTools_SourceControl.ael
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   CodingTools_SourceControl.ael
    

    但如果我现在发布 git diff 命令,我得到一个diff报告,显示文件中所有1500多行的更改:

    S:\mydir\AEL>git diff --cached --stat CodingTools_SourceControl.ael
     AEL/CodingTools_SourceControl.ael | 3082 ++++++++++++++++++-------------------
     1 file changed, 1541 insertions(+), 1541 deletions(-)
    

    编辑: 在@RomainVALERI的有用评论之后,我尝试了以下命令

    S:\mydir\AEL>git diff --cached --stat --ignore-cr-at-eol CodingTools_SourceControl.ael
     AEL/CodingTools_SourceControl.ael | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    

    它报告一行发生了变化。所以这是一个行尾问题。但我需要Dulwich操作与命令行操作互换。我该怎么告诉达利奇 Repo.stage() git add 做?

    porcelain.add() 而不是 回购阶段()

    porcelain.add(repo, r"S:\mydir\AEL\CodingTools_SourceControl.ael")
    

    但没什么用。

    2 回复  |  直到 6 年前
        1
  •  1
  •   BoarGules    6 年前

    从中的代码 dulwich.index.blob_from_path_and_stat() 看来达利奇根本不注意这个问题 core.autocrlf 设置,不注意 .gitattributes 只需将工作目录文件中所有内容的逐字节副本写入Git数据库。

    Mind the end of your line 作者:timclem,作者:GitHub,这是我在试图理解问题和解决问题时读到的十几篇文章中最清晰的解释。

        2
  •  -1
  •   Petr Kozelka    6 年前

    .gitattributes 文件-请参阅 https://git-scm.com/docs/gitattributes

    每当我创建新的源代码存储库时,我总是将其与以下内容一起使用:

    * text=auto
    

    因为,以后引入它会带来一些麻烦,特别是当您的存储库与团队共享时——因为它会更改所有(或大部分)文件,而且,此更改会在新签出后出现,而不是在当前工作副本上。