gpt4 book ai didi

git - 是否可以仅恢复提交的代码块更改?

转载 作者:行者123 更新时间:2023-12-02 09:41:30 25 4
gpt4 key购买 nike

所以我正在使用 Visual Studio CodeSourcetree

假设我有一个名为 Occupation.ts 的文件

Occupation.ts(初始提交)

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';
}
}

现在我对此文件进行了一些更改。

Occupation.ts(最新更改)

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';
}
}

因此,我对 getOc​​cupationCategoryTablesaveOccupationTable 函数进行了更改。现在我只想恢复 getOc​​cupationCategoryTable 中的更改。有什么git方法可以实现这一点吗?

最佳答案

恢复错误的提交并传递-n旗帜。这应该创建一个新的提交,但它会暂存那些“撤消”更改。接下来简单的git reset将取消暂存这些更改,然后使用 SourceTree 有选择地撤消该文件中的 block :

  1. git revert -n <Commit Id>
  2. git reset
  3. 打开 SoureTree 并选择修改后的文件
  4. “撤消”错误代码的阶段 block 。
  5. 提交。

关于git - 是否可以仅恢复提交的代码块更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60537936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com