准确的git提交 [英] Accurate git commits

查看:129
本文介绍了准确的git提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一些代码如

  / ** 
* blah等等等等
* /
...一些代码...
/ **
* yadda yadda

然后我加上

  / ** 
*等等等等等等
* /
...一些代码...
/ **
*等等等等等等
* /
...一些代码...

在yadda yaddacommanet之前,git diff会显示我添加了:

  + * blah blah blah 
+ * /
+ ...一些代码...
+ / **

有没有办法告诉git:嘿,那是不对的,再试一次。?我知道 - 耐心,但这似乎只是为了git diff,并且对我来说它永远不会正常工作。我知道这并不是特别重要,但它使差异和提交日志,特别是在GitHub上,更加干净。

解决方案

Git在存储库中存储文件是基于整个文件的。当你询问两个版本之间的差异时,Git从存储库 1 中检索 complete 文件,并在它们之间运行diff算法。与其他源代码控制系统不同,Git在提交时不会计算或存储文件之间的差异。



这种方法的优点是可以轻松地改变在你要求的时候差异。例如,您已经看到 - 耐心标志,该标志使用不同的差异算法来确定两个文件之间(可能)更好的补丁。



由于文件存储在Git存储库中的方式,无法告诉Git以某种方式跟踪自定义diff比对。


  1. 在Git仓库中,在 .pack 文件内部,Git使用各种增量编码方法来存储相似对象之间的差异,从而缩小尺寸的存储库。但是,这比文件存储的级别低,并且不是源文件之间的实际差异。


If I have some code like

/**
 * blah blah blah
 */
...some codes...
/**
 * yadda yadda

And then I add

/**
 * blah blah blah
 */
...some codes...
/**
 * blah blah blah
 */
...some codes...

before the "yadda yadda" commanet, the git diff will show that I added:

 +  * blah blah blah
 +  */
 +  ...some codes...
 + /**

Is there a way to tell git, "hey, that's not right. Try again."? I know of --patience but that seems to just be for git diff and for the life of me it never works correctly. I know it's no super important, but it makes diffs and commit logs, especially on GitHub, much more clean.

解决方案

The way Git stores files in the repository is on a whole-file basis. When you ask for a difference between two versions, Git retrieves both complete files from the repository1, and runs the diff algorithm between them. Unlike some other source control systems, Git does not calculate or store the differences between files at the time of commit.

This method has the advantage of easily changing the behaviour of the diff at the time you ask for it. For example, you have seen the --patience flag that uses a different diff algorithm to determine a (possibly) better patch between two files.

Because of the way files are stored in the Git repository, it is not possible to tell Git to somehow keep track of a custom diff alignment.

  1. Deep down in the Git repository, inside .pack files, Git uses various delta encoding methods to store differences between similar objects and thus reduce the size of the repository. However, this is on a lower level than the file storage and are not actual diffs between source files.

这篇关于准确的git提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆