我开始*.py diff=python了.git/info/attributes.所以Git知道功能界限在哪里.git diff -W甚至可以确保显示整个功能.
但有没有办法将git diff的输出限制为特定的函数(或多个函数)?
(没错,我猜它很糟糕......)
编辑这也将是有益的git log和git rev-list:不显示我的每一个承诺会修改views.py,告诉我犯这是修改某个功能.(是的,在一个理想的世界里,views.py不会是一个经常被8个不同的开发者修改的2000行庞然大物...)
我已配置git为meld用作外部差异工具:
$ cat ~/.gitconfig | grep -A2 "\[diff\]"
[diff]
tool = vimdiff
external = git-meld
Run Code Online (Sandbox Code Playgroud)
......在哪里git-meld:
$ cat $(which git-meld)
#!/bin/bash
meld $2 $5
Run Code Online (Sandbox Code Playgroud)
但有时候(例如在非常小的差异或者我想从diff文本中轻松复制粘贴的东西的情况下)我只想看到shell上的差异并避免meld产生延迟.
有没有办法(例如命令行参数)覆盖.gitconfig设置并指示git只做一个简单的纯文本差异?
我期待只从git repo改变文件的差异.现在,我正在使用gitpython来实际获取提交对象和git文件的更改,但我想对仅更改的文件部分进行依赖性分析.有没有办法从git python获取git diff?或者我是否必须通过逐行阅读来比较每个文件?
我在这篇文章中关注了JörgWMittag 的回答,并将meld配置为我的git中的difftool.现在,我可以使用此命令完美地查看和比较不同分支中文件的差异:
git checkout branch1
git difftool branch1:file.f90 branch2:file.f90
Run Code Online (Sandbox Code Playgroud)
我执行了上面的命令,制作并保存了变化.但是,当我使用以下方法检查文件时:
emacs file.f90
Run Code Online (Sandbox Code Playgroud)
我之前在meld中所做的更改根本没有保存.我不明白为什么会这样; 我必须没有完全正确配置融合作为差异工具.任何人都可以帮我解决这个问题吗?谢谢!!
我有一个已安装另一个存储库的存储库
git subtree add -P some/path otherremote otherbranch
Run Code Online (Sandbox Code Playgroud)
开发已经发生了一些局部变化,但也进行了几轮合并:
git fetch otherremote
git subtree merge -P some/path otherremote/otherbranch
git commit
Run Code Online (Sandbox Code Playgroud)
现在我想在otherremote/otherbranch的HEAD和某些/ path的树之间获得差异.我怎样才能做到这一点?
我需要在我的仓库中获得一些与仓库基础无关的差异,而是相对于给定的基础或给定路径.
我默认得到:
git diff
diff --git a/path/to/file b/path/to/file
index 0cc125e..9bf911e 100644
--- a/path/to/file
+++ b/path/to/file
Run Code Online (Sandbox Code Playgroud)
但我想要的是:
git diff --prefix=/new/path/to
diff --git a/new/path/to/file b/new/path/to/file
index 0cc125e..9bf911e 100644
--- a/new/path/to/file
+++ b/new/path/to/file
Run Code Online (Sandbox Code Playgroud)
我查看了--relative选项(不是我要找的), - src/dst-prefix(这些只能改变"a"或"b"部分.我错过了一些基本的东西吗?
有没有办法查看同一文件的版本staged和unstaged版本之间的差异?
例如:
Changes to be committed:
modified: conf/application.conf
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: conf/application.conf
Run Code Online (Sandbox Code Playgroud)
当我进行更改然后再次修改文件而不进行暂存时会发生这种情况.
EDIT
该git status -vv命令还不够好,因为我需要使用diff/ difftool命令.这是因为在实践中,太多文件中的更改太多,滚动浏览所有文件并不高效.但diff/ difftool允许我指定我感兴趣的文件.
假设我有一个名为LICENSE.txt的存储库中的文件.内容如下:
Copyright 2014 MyCompany. All Rights Reserved.
Run Code Online (Sandbox Code Playgroud)
自2015年以来,我改变了今年的2015年:
Copyright 2015 MyCompany. All Rights Reserved.
Run Code Online (Sandbox Code Playgroud)
然后上传文件
git add LICENSE.txt
Run Code Online (Sandbox Code Playgroud)
由于分心,我对LICENSE.txt做了另一个更改,以反映另一个组织的版权.
Copyright 2015 MyCompany and Affiliates. All Rights Reserved.
Copyright 2015 Other Company. All Rights Reserved.
Run Code Online (Sandbox Code Playgroud)
通过运行,我能够看到我的工作副本和分阶段副本之间的区别
git diff
Run Code Online (Sandbox Code Playgroud)
我可以通过运行看到分阶段副本和提交副本之间的区别
git diff --cached
Run Code Online (Sandbox Code Playgroud)
如何将承诺的副本(没有更改年份的副本)与工作副本(具有附加版权的副本)进行比较?
这纯粹是一个例子.有些情况要复杂得多,我需要将我上演的内容与我随后对文件所做的更改进行比较.比较工作副本和分阶段副本的内容将决定是否应该替换分阶段副本.
我在Windows Server 2012 R2上运行git 1.9.5.
我有一个脚本,update.py它下载我的git存储库中跟踪的新版本文件:
$ python update.py
Doing work...
Done
$ git status
On branch my-branch
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: foo.txt
modified: bar.txt
modified: baz.txt
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
有时,下载的文件与已有的文件相同HEAD,因此下载后工作目录是干净的:
$ python update.py
Doing work...
Done
$ git status
On branch my-branch
nothing to commit, working directory clean …Run Code Online (Sandbox Code Playgroud) 根据官方git 文档:
git diff
-w, --ignore-all-space
Ignore whitespace when comparing lines. This ignores differences
even if one line has whitespace where the other line has none.
Run Code Online (Sandbox Code Playgroud)
然而,基本测试表明事实并非如此。
somefile.txt使用以下内容
创建:git add somefile.txtcp somefile.txt somefile.orig.txtsomefile.txt:
git diff -w somefile.txt > somefile.gitdiffdiff -uw somefile.orig.txt somefile.txt > …