首页 > 解决方案 > Tell git that modified line is not new line

问题描述

I modified a parameter on a function and now git recognizes it as an entirely new line of code. The first line of code below represents the original code, and the second line represents the "new" line after I changed one parameter. The first line was originally on line 1 and the new line is now on line 10 (because I didn't make an atomic commit, and I believe this is the main problem).

// on line 1 originally
const myFunction = (someArray: Array<{ id: string; name: string; }>, index: number) => {

// now on line 10
const myFunction = (someArray: Array<{ id: string; name: string; }>, index: string) => {

Is there any way to tell git that line 10 is just line 1 modified so that it doesn't seem like so much churn is happening?

标签: gitversion-control

解决方案


这真的没有意义。Git 会在每次提交时跟踪文件的全部内容。唯一可以将事物称为“添加”、“修改”或“删除”的时间是当您区分两件事时。对于已移动的行,这将始终被差异工具视为删除和插入。


推荐阅读