Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 是否可以仅还原提交的代码块更改?_Git_Visual Studio Code_Atlassian Sourcetree - Fatal编程技术网

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重置
  • 打开SoureTree并选择修改后的文件
  • “撤消”坏代码的阶段块
  • 承诺

  • 您可以尝试
    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';
        }
    }