小编vas*_*kch的帖子

使用git rebase编辑合并提交

在我提交的Git中,例如.A - B - C我想编辑B提交,我

  • git rebase -i <A-commit-hash>,
  • 在列表中我editBcommit 前写命令,
  • B提交后,git rebase会立即停止,因此我可以修复任何我想要的东西git commit --amend,
  • 然后我继续使用git rebase --continue.

据我所知,这是如何做到这一点的最佳实践.使用这种方法,我可以编辑过去的任何提交(只要它还没有被推送到远程分支),而且使用-p标志我甚至可以保留合并.这太棒了.

我目前的问题是:我在合并提交中的一行上做了一个错误(拼写错误)(当合并两个分支时解决冲突).

我想解决它,但我不知道如何git rebase停止合并提交.该git rebase -p -i <blah>列表忽略了合并提交,所以我不能edit在它前面写命令并git rebase停在那里让我编辑它.

有什么帮助吗?我只想在合并提交中修复此行,同时保留它之后的所有提交(和合并).

谢谢.

git rebase

53
推荐指数
2
解决办法
2万
查看次数

TypeScript 映射类型:带嵌套的标记类型

TypeScript 有没有办法创建高级类型文档中Flags提到的类型的嵌套版本?

这很有效:

type Flags<T> = {
  [P in keyof T]: boolean;
}

interface Colors {
  red: string;
  green: string;
  blue: string;
}

const activeColors: Flags<Colors> = {
  red: true,
  green: true,
  blue: false
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我想创建一个NestedFlags能够处理这样的嵌套对象的类型呢?

interface NestedColors {
  red: string;
  green: string;
  blue: string;
  more: {
    yellow: string;
    violet: string;
    black: string;
  }
}

const activeNestedColors: NestedFlags<NestedColors> {
  red: true,
  blue: false,
  green: true,
  more: {
    yellow: false,
    violet: true,
    black: true
  } …
Run Code Online (Sandbox Code Playgroud)

typescript mapped-types

4
推荐指数
1
解决办法
621
查看次数

从可为空类型中提取不可为空类型定义

假设我有一个由外部工具生成的以下界面:

\n
interface Animals {\n    turtle: { shellHardness: number };\n    fox: { whatDidItSay: string } | null;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我想Animals为乌龟和狐狸定义(从中提取)类型,但不\xe2\x80\xa6| null为狐狸定义类型。这对乌龟来说很容易,因为没有 null:

\n
type Turtle = Animals["turtle"];\n
Run Code Online (Sandbox Code Playgroud)\n

但我该如何为狐狸做这件事呢?我想象可能有某种ExtractNullable类型可以消除可为空性:

\n
type Fox = ExtractNullable<Animals, "fox">;\n
Run Code Online (Sandbox Code Playgroud)\n

不幸的是我无法ExtractNullable正确定义类型。我尝试了以下方法:

\n
type ExtractNullable<T, K extends keyof T> = T[K] extends null ? never : T[K];\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\xa6但它不起作用。TypeScript Playground 仍然告诉我类型Fox被定义为type Fox = { whatTheySaid: string; } | null而不是type Fox = { whatTheySaid: …

null types typescript typescript-generics

2
推荐指数
1
解决办法
1038
查看次数