Accurate git commits

那年仲夏 提交于 2019-12-24 14:26:19

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/18116221/accurate-git-commits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!