跳至内容
GitTree

课程 24 · 恢复

继续、跳过或中止活动操作

当合并或变基停止时,您有三种退出方法:继续、跳过或中止。了解哪一个适合,每个扔掉什么,以及事后如何检查存储库。

进度已保存在此浏览器中。

播放时会加载来自 YouTube 的视频(隐私增强模式)。

英文旁白 · English and Arabic 字幕

打开视频页面在 YouTube 上观看

你将学到什么

  • 在触摸任何内容之前,请告知哪个操作处于活动状态。
  • 仅在解决并标记每个冲突后才继续。
  • 解释一下 Skip 遗漏了什么,以及什么时候它是错误的工具。
  • 中止操作并检查您是否回到开始处。

开始之前

您使用第 23 课中的分歧:conflict/sara(Sara 的标题“自信地审查更改”)和 conflict/omar(Omar 的标题“了解每个保存的更改”),均来自提交 M。为其制作三个干净的副本,分别命名为 gittree-continue、gittree-abort 和 gittree-skip。在每个中,conflict/sara 已签出并且没有任何运行。您将停止所有三个操作中的相同操作,并以不同的方式离开每个操作。

一切都是本地的并且采用免费套餐(GitTree 要求您登录):没有托管帐户、没有提供商、没有互联网。每个身份都是虚构的(example.com)。切勿在实际项目中运行本课程。

在 GitTree 中或使用本机 Git 命令进行更改,而不是在同一副本中进行更改。读取结果总是安全的。菜单标签来自 GitTree 2.0 自己的字符串,本机命令使用 Git 2.43 在一次性副本中运行。 GitTree 步骤未在 macOS、Windows 或 Linux 上运行。

概念和状态效应

停止的操作本身就是一种状态。在结束之前,存储库会记住它正在做什么,并且您不得在其之上启动另一个合并或变基。首先找出什么是活跃的。 GitTree的横幅清楚地写着:“将…合并到…”,或“将…重新定基到…”(当有多个时,带有步骤编号),以及剩余的冲突数量。在终端中,git status 以“您有未合并的路径”和合并提示开头,或者以“交互式变基正在进行中;到…”开头以表示变基,然后列出您可以使用的命令。

一旦每个冲突都得到解决并且其结果已上演,Continue就会继续。它不是原始合并或变基的重试:它完成合并提交,或将变基移至下一个提交。

Skip 存在于重播提交的操作中,例如变基。它将当前提交的更改完全排除在结果之外。在本课中,Skip 放弃了 Sara 的标题,分支以 Omar 的提交结束。它不是“接受文件”或推迟冲突的方法,而且只要您仍然想要进行更改,它就是错误的工具。合并没有跳过,因为合并只是一步:您要么完成它,要么中止它。

Abort 返回操作开始的位置。到目前为止您解决的任何问题都将被放弃。 GitTree 保存它首先删除的内容的恢复快照,并且存储库返回到之前的确切提交、索引和文件。当你不确定自己在做什么时,这是出路。

选择结果费用是多少
继续合并提交,或重播下一个提交没什么,一旦一切都解决了
跳过当前提交的更改被忽略改变,直到你再次找到它
中止存储库又回到了起点操作期间完成的工作

准备准确的项目状态

建造萨拉和奥马尔的树枝一次,然后复制三份。从第 18 课留下的项目的单独普通副本开始,并保持原始的 gittree-features 不变。页面版本:MERGED 是共享基础,SARA 和 OMAR 是竞争版本,RESOLVED 是您在连续副本中保存的结果。

完整的文件输入

仅在下面指定的阶段保存。这些是完整的 UTF-8/LF 正文,最后有换行符;永远不要粘贴 Markdown 栅栏。未更改的可运行文件继承命名输入。单独变体中的版本不得覆盖原始版本。

index.html — 合并

文件摘录 · html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>GitTree Features — course demo</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="site-header">
    <a href="#main">GitTree Features</a>
  </header>
  <main id="main" tabindex="-1">
    <section class="hero" aria-labelledby="hero-title">
      <p class="eyebrow">GitTree Learn demo project</p>
      <h1 id="hero-title">See your work clearly.</h1>
      <p id="hero-copy">Choose one change, then check what Git saved.</p>
    </section>
    <section class="features" aria-labelledby="features-title">
      <h2 id="features-title">Follow your work</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>History</h3>
          <p>Read commits and branches together.</p>
        </article>
        <article class="feature-card">
          <h3>Changes</h3>
          <p>Review the exact content selected for a commit.</p>
        </article>
        <article class="feature-card">
          <h3>Recovery</h3>
          <p>Inspect the scope of a recovery point before using it.</p>
        </article>
      </div>
    </section>
    <section aria-labelledby="plans-title">
      <h2 id="plans-title">Choose the workflow you need</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>Local Git</h3>
          <p>Local Git workflows work without signing in.</p>
        </article>
        <article class="feature-card">
          <h3>Connected workflows</h3>
          <p>Provider integrations and Nour require Pro or an applicable trial.</p>
        </article>
      </div>
    </section>
  </main>
  <footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
  <script type="module" src="site.js"></script>
</body>
</html>

index.html — SARA

文件摘录 · html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>GitTree Features — course demo</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="site-header">
    <a href="#main">GitTree Features</a>
  </header>
  <main id="main" tabindex="-1">
    <section class="hero" aria-labelledby="hero-title">
      <p class="eyebrow">GitTree Learn demo project</p>
      <h1 id="hero-title">Review changes with confidence.</h1>
      <p id="hero-copy">Choose one change, then check what Git saved.</p>
    </section>
    <section class="features" aria-labelledby="features-title">
      <h2 id="features-title">Follow your work</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>History</h3>
          <p>Read commits and branches together.</p>
        </article>
        <article class="feature-card">
          <h3>Changes</h3>
          <p>Review the exact content selected for a commit.</p>
        </article>
        <article class="feature-card">
          <h3>Recovery</h3>
          <p>Inspect the scope of a recovery point before using it.</p>
        </article>
      </div>
    </section>
    <section aria-labelledby="plans-title">
      <h2 id="plans-title">Choose the workflow you need</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>Local Git</h3>
          <p>Local Git workflows work without signing in.</p>
        </article>
        <article class="feature-card">
          <h3>Connected workflows</h3>
          <p>Provider integrations and Nour require Pro or an applicable trial.</p>
        </article>
      </div>
    </section>
  </main>
  <footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
  <script type="module" src="site.js"></script>
</body>
</html>

index.html — 奥马尔

文件摘录 · html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>GitTree Features — course demo</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="site-header">
    <a href="#main">GitTree Features</a>
  </header>
  <main id="main" tabindex="-1">
    <section class="hero" aria-labelledby="hero-title">
      <p class="eyebrow">GitTree Learn demo project</p>
      <h1 id="hero-title">Understand each saved change.</h1>
      <p id="hero-copy">Choose one change, then check what Git saved.</p>
    </section>
    <section class="features" aria-labelledby="features-title">
      <h2 id="features-title">Follow your work</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>History</h3>
          <p>Read commits and branches together.</p>
        </article>
        <article class="feature-card">
          <h3>Changes</h3>
          <p>Review the exact content selected for a commit.</p>
        </article>
        <article class="feature-card">
          <h3>Recovery</h3>
          <p>Inspect the scope of a recovery point before using it.</p>
        </article>
      </div>
    </section>
    <section aria-labelledby="plans-title">
      <h2 id="plans-title">Choose the workflow you need</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>Local Git</h3>
          <p>Local Git workflows work without signing in.</p>
        </article>
        <article class="feature-card">
          <h3>Connected workflows</h3>
          <p>Provider integrations and Nour require Pro or an applicable trial.</p>
        </article>
      </div>
    </section>
  </main>
  <footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
  <script type="module" src="site.js"></script>
</body>
</html>

index.html — 已解决

文件摘录 · html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>GitTree Features — course demo</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="site-header">
    <a href="#main">GitTree Features</a>
  </header>
  <main id="main" tabindex="-1">
    <section class="hero" aria-labelledby="hero-title">
      <p class="eyebrow">GitTree Learn demo project</p>
      <h1 id="hero-title">Review each change with confidence.</h1>
      <p id="hero-copy">Choose one change, then check what Git saved.</p>
    </section>
    <section class="features" aria-labelledby="features-title">
      <h2 id="features-title">Follow your work</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>History</h3>
          <p>Read commits and branches together.</p>
        </article>
        <article class="feature-card">
          <h3>Changes</h3>
          <p>Review the exact content selected for a commit.</p>
        </article>
        <article class="feature-card">
          <h3>Recovery</h3>
          <p>Inspect the scope of a recovery point before using it.</p>
        </article>
      </div>
    </section>
    <section aria-labelledby="plans-title">
      <h2 id="plans-title">Choose the workflow you need</h2>
      <div class="cards">
        <article class="feature-card">
          <h3>Local Git</h3>
          <p>Local Git workflows work without signing in.</p>
        </article>
        <article class="feature-card">
          <h3>Connected workflows</h3>
          <p>Provider integrations and Nour require Pro or an applicable trial.</p>
        </article>
      </div>
    </section>
  </main>
  <footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
  <script type="module" src="site.js"></script>
</body>
</html>

在GitTree

使用 Command+Shift+P(在 Ubuntu 上为 Ctrl+Shift+P)打开调色板。对指定分支的操作​​使用该分支的右键单击菜单。

  1. 构建三个副本,如下一节所示。在每个中,conflict/sara 已签出并且状态为空。请注意中止副本中 conflict/sara 的完整 ID。
  2. Continue copy. 打开gittree-continue。右键单击 conflict/omar 并选择 Merge conflict/omar into conflict/sara 和 Always a merge commit。它停止了。在横幅上选择 Resolve,打开 index.html,选择 Edit Output,写入 Review each change with confidence.,然后选择 Save and Mark Resolved。
  3. 检查是否没有冲突,然后选择横幅上的 Continue 一次。通知上写着“完成”。然后横幅就消失了。新提交有两个父母。
  4. Abort copy. 打开 gittree-abort 并开始相同的合并。让冲突悬而未决。在横幅上选择 Abort…。对话框“中止操作?”解释说分支、索引和文件会恢复到原来的状态,并且删除的内容会首先保留在恢复快照中。选择Abort。该通知显示“已中止。它删除的更改保存在 refs/ogt/trash/... 下;撤消会将其恢复。” (当中止没有删除任何内容时,它会显示“已中止。存储库回到了之前的位置。”)
  5. 检查中止:conflict/sara 仍然是您记下的 ID,该页面是 Sara 的完整标题,并且没有横幅。
  6. Skip copy. 打开gittree-skip。右键单击 conflict/omar 并选择 Rebase conflict/sara onto conflict/omar。将选项保留为关闭状态并选择 Rebase conflict/sara。它停止了。横幅现在在 Continue 和 Abort… 旁边提供 Skip;合并横幅没有跳过。
  7. 阅读正在重播的提交(Sara 的),承认跳过会遗漏她的标题,然后选择 Skip 一次。通知上写着“跳过该步骤”。
  8. 检查跳过:页面显示 Omar 的标题,conflict/sara 现在指向 Omar 的提交,并且没有显示横幅。比较三个结果并将它们分开。

对于课程中的每个普通提交:Summary 是规定的主题,Description 为空,并且选项 Amend Previous Commit、Skip Hooks、Add Signed-off-by、Different Author、Push After Commit 和 Allow Empty Commit 保持关闭状态。

在航站楼

在第 18 课结果的单独干净副本中:

Command · bash
git switch --create conflict/sara
BASE_SHA="$(git rev-parse HEAD)"

将 SARA 保存为 index.html,然后:

Command · bash
git add -- index.html
git -c user.name="Sara Lindqvist" -c user.email=sara@example.com commit --quiet -m "feat: Sara clarifies the hero"
git switch --quiet --create conflict/omar "$BASE_SHA"

将 OMAR 保存为 index.html,然后:

Command · bash
git add -- index.html
git -c user.name="Omar Haddad" -c user.email=omar@example.com commit --quiet -m "feat: Omar explains the hero"
git switch --quiet conflict/sara

制作此状态的三个干净副本(gittree-continue、gittree-abort、gittree-skip)。首先,每当您不确定时查看什么是活动的:

Command · bash
git status

Continue copy. 合并停止,退出代码为 1。将 RESOLVED 保存为 index.html,然后:

Command · bash
git merge --no-ff --no-edit conflict/omar
git add -- index.html
git -c core.editor=true merge --continue
git ls-files --unmerged
git status --short

最后两个命令不打印任何内容。 Abort copy:

Command · bash
git rev-parse conflict/sara
git merge --no-edit conflict/omar
git merge --abort
git rev-parse HEAD conflict/sara
git status --short

合并停止,并且 git merge --abort 结束它。 git rev-parse HEAD conflict/sara打印的两个ID相等,index.html是Sara的整页,状态为空。停止的变基以与 git rebase --abort 相同的方式保留。 Skip copy:

Command · bash
git rebase conflict/omar
git rebase --skip
git rev-parse HEAD conflict/omar
git status --short

变基停止; git rebase --skip 以“成功重新调整基准”结束。这两个 ID 相等,因此 Sara 的分支现在位于 Omar 的提交上,该页面是 Omar 的,并且状态为空。 Sara 跳过的提交不再在分支上,但 Git 仍然保留它一段时间(reflog,第 29 课)。不要将该结果视为保留两个输入的解决方案。

结果

Where you end:三份,三种不同的结果。继续副本具有带有组合标题的双父合并提交。中止副本正是从萨拉开始的地方开始的。跳过副本具有奥马尔的标题和奥马尔提交上的萨拉的分支。在这三个操作中,操作均已结束,状态已干净。

常见错误

  • 使用“跳过”来“克服”冲突。它从结果中删除该提交的更改。
  • 在其中一个合并或变基仍处于停止状态时开始另一次合并或变基。
  • 使用 git reset --hard 进行转义,而不是 git merge --abort 或 git rebase --abort。
  • 当您单击一下即可完成时中止,或者当您不确定正在上演的内容时继续。

如果出现问题

如果您迷路了,请先阅读横幅或 git status,然后再决定。中止始终是返回起点的安全方法。如果您错误地跳过了,请不要盲目地重新开始:跳过的提交在一段时间内仍然可以从引用日志中访问(第 29 课),第 30 课展示了 GitTree 的撤消可以放回什么。

检查你的理解情况

回答每个问题,然后阅读原因。标记为“必填”的问题将有助于完成本课程。

  1. 第 1 题,共 6 题

    变基因冲突而停止。您解析了该文件并将其暂存。哪个命令进行变基?

    选择一个答案。

  2. 第 2 题,共 6 题

    git rebase --skip 是做什么的?

    选择每个适用的答案。

  3. 第 3 题,共 6 题
    必填

    在跳过副本中,您选择跳过一次。之后页面和分支是什么样子的?

    选择一个答案。

  4. 第 4 题,共 6 题

    更改输入:在继续复制中,您解析文件并将其标记为已解析,然后选择中止...而不是继续。你的决心会发生什么变化?

    选择一个答案。

  5. 第 5 题,共 6 题
    必填

    您正处于合并过程中,并在横幅上寻找“跳过”按钮,但它不在那里。为什么?

    选择一个答案。

  6. 第 6 题,共 6 题
    必填

    在中止副本中中止合并后,哪些回读显示您回到了开始处?

    选择每个适用的答案。

0 个(共 6 个)正确

正确回答所需的问题以完成课程。

在此浏览器中检查。

练习

在每个副本中,说明操作、选择和证明:对于继续,两个父级和空的未合并列表,对于中止相同的 ID 和 Sara 的页面,对于跳过 Omar 的页面和他提交的分支。然后预测为什么不为合并提供 Skip。

您自己的确认:该网站无法看到您的计算机。

要完成本课程,请正确回答所需的问题并确认实践练习。

回顾

  • 在行动之前找出哪些活动是活跃的。
  • 解决后继续,仅跳过以留下提交,中止以返回。
  • 之后检查提交、文件和状态。

术语表介绍

继续 — 重要;跳过——中止 — ???;操作 — 详情

视频文字记录

视频的旁白,逐条提示。

显示成绩单
  1. 合并或变基停止。你有三个 出路。
  2. 继续完成吧。跳过叶子一 提交。中止返回。
  3. 首先,始终找出哪个操作是 活跃。
  4. 横幅为其命名。在终端中,git 状态确实如此。
  5. 建立萨拉和奥马尔的分支机构,以及 三份相同的副本。
  6. 相同的开始,三种不同的结局。
  7. 抄一:我们继续。开始合并, 然后它就停止了。
  8. 解决,打开文件,写入 合并标题。
  9. 保存并标记为已解决,以便 Git 看到 文件已完成。
  10. 现在可以继续。选择一次。
  11. 完毕。新提交有两个父母,并且 横幅不见了。
  12. 副本二:我们中止。开始相同的合并。
  13. 抛开冲突,选择 中止。
  14. 该对话框解释了返回的内容,以及 首先保留什么。
  15. 存储库又回到了原来的位置 之前。
  16. 分支尖端是相同的ID,并且 页面又是莎拉的。
  17. 副本三:我们跳过。这是一个变基。
  18. 将 Sara 的分支重新设置到 Omar 的分支上。它停止了 与冲突。
  19. 现在横幅有一个“跳过”按钮。合并 从来没有过。
  20. Skip 将 Sara 的提交排除在外 结果。大声说出来。
  21. 选择跳过一次。
  22. 该页面显示奥马尔的标题。萨拉的 分支现在坐在他的提交上。
  23. 跳过不是解决方案。它删除了 莎拉因这个结果而改变。
  24. 在终端中, git status 显示什么 活动和命令。
  25. 合并:添加已解析的文件,然后git 合并继续。
  26. 中止:分支尖端相同 之前和之后。
  27. 跳过:git rebase跳过,和分支 坐在奥马尔的承诺上。
  28. 在每个副本中,状态都是空的,并且 没有什么是未合并的。
  29. 更改输入:解析文件,然后 选择中止。
  30. 经过一段时间后,您的决议被放弃 恢复快照已保存。
  31. 切勿使用复位硬法来逃脱。中止是 安全的出路。
  32. 如果你错误地跳过了,则提交是 仍在转发日志中。
  33. 练习:命名操作、选择、 以及每份副本的证明。
  34. 接下来,将单个提交复制到另一个提交 樱桃采摘的分支。