Git 是否可以仅还原提交的代码块更改?
因此,我正在使用Git 是否可以仅还原提交的代码块更改?,git,visual-studio-code,atlassian-sourcetree,Git,Visual Studio Code,Atlassian Sourcetree,因此,我正在使用visualstudio code和Sourcetree 假设我有一个名为occulation.ts的文件 占领.ts(初始提交) 现在我对这个文件做了一些更改 职业.ts(最新变化) 因此,我对getOccupationCategoryTable和saveOccupationTable函数进行了更改。现在,我只想在getOccupationCategoryTable中恢复我的更改。有什么git方法可以实现这一点吗?还原错误提交并传递-n标志。这应该会创建一个新的提交,但它会将这
visualstudio code
和Sourcetree
假设我有一个名为occulation.ts的文件
占领.ts(初始提交)
现在我对这个文件做了一些更改
职业.ts(最新变化)
因此,我对
getOccupationCategoryTable
和saveOccupationTable
函数进行了更改。现在,我只想在getOccupationCategoryTable
中恢复我的更改。有什么git
方法可以实现这一点吗?还原错误提交并传递-n
标志。这应该会创建一个新的提交,但它会将这些“撤消”更改分阶段进行。接下来,一个简单的git reset
将取消这些更改,然后使用SourceTree有选择地撤消该文件中的块:
git还原-n
git重置
您可以尝试
git reset-p
git不能处理文件差异。它适用于不同的文件。整个文件。使用合并工具合并已编辑、暂存或提交的两个文件git difftool
@marblewraith如果我尝试此操作,它将还原所有更改,我只是尝试还原一段代码。@rioV8的意思是,这是不可能的?@Rich不,这就是-p
标志的用途。
private getOccupationCategoryTable(index: number): string {
switch (index) {
case 0:
case 1: return 'occupationCategoryLookUpCommon';
case 2: return 'occupationCategoryLookUpCreditCard';
case 3: return 'occupationCategoryLookUpASB';
}
}
private saveOccupationTable(index: number): string {
switch (index) {
case 0:
case 1: return 'saveOccupationCategoryLookupCommon';
case 2: return 'saveOccupationCategoryLookupCreditCard';
case 3: return 'saveOccupationCategoryLookupASB';
}
}
private updateOccupationTable(index: number): string {
switch (index) {
case 0:
case 1: return 'updateOccupationLookupDetailCommon';
case 2: return 'updateOccupationLookupDetailCreditCard';
case 3: return 'updateOccupationLookupDetailASB';
}
}
private getOccupationCategoryTable(index: number): string {
switch (index) {
case 0:
case 1: return 'occupationLookUpCommon';
case 2: return 'occupationLookUpCreditCard';
case 3: return 'occupationLookUpASB';
}
}
private saveOccupationTable(index: number): string {
switch (index) {
case 0:
case 1: return 'saveOccupationLookupCommon';
case 2: return 'saveOccupationLookupCreditCard';
case 3: return 'saveOccupationLookupASB';
}
}
private updateOccupationTable(index: number): string {
switch (index) {
case 0:
case 1: return 'updateOccupationLookupDetailCommon';
case 2: return 'updateOccupationLookupDetailCreditCard';
case 3: return 'updateOccupationLookupDetailASB';
}
}