我有一个单行更改的文件: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...
我希望能够使用 Dulwich 来管理暂存和提交。所以在 Idle 之后reset
,我这样做:
>>> from dulwich.repo import Repo
>>> repo = Repo(br"S:\mydir")
>>> repo.stage([br"AEL\CodingTools_SourceControl.ael"])
之后,git status
将更改显示为阶段性,就像以前一样
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
命令,我会得到一个差异报告,其中显示文件的所有 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()
而不是Repo.stage()
porcelain.add(repo, r"S:\mydir\AEL\CodingTools_SourceControl.ael")
但这没有任何帮助。