Using Git diff to detect code movement + How to use diff options

后端 未结 3 1722
北海茫月
北海茫月 2020-11-30 04:00

Consider that a file (1.c) contains three functions and changes made by authors M and J. If someone runs git blame 1.c, he will get the following output:

<
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 04:41

    In this particular case, I don't think git diff is concerned about detecting code movement; rather, it's simply creating a patch that can be applied to transform the old file into the new file, which is what your git diff output plainly shows - the function is being deleted from one location and inserted in another. There are probably more succinct ways to output a series of edit commands that move code from one location to another, but I think git might be erring on the side of portability here - there's no guarantee the end user wound always use git apply or git am, so the patch is produced in a format that can be used even with plain patch.

提交回复
热议问题