Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Git 中管理历史记录
  7. 组合和合并提交
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

组合和合并提交

请转至您之前下载的git-tutorial/tutorial7目录。

当您检查此存储库的历史记录时,它将如下所示:

Current history

我们会将来自issue1分支的提交压缩为单个提交,然后将其合并到主分支中。

切换到主分支,并使用--squash选项执行合并,如下所示。

$ git checkout main
  Switched to branch 'main'
$ git merge --squash issue1
  Auto-merging sample.txt
  CONFLICT (content): Merge conflict in sample.txt
  Squash commit -- not updating HEAD
  Automatic merge failed; fix conflicts and then commit the result.

Git 会检测到冲突。我们必须在sample.txt文件中手动解决冲突,并提交更改。

$ git add sample.txt
$ git commit
  [main 0d744a7] Conflicts:   sample.txt
    1 files changed, 4 insertions(+), 0 deletions(-)

我们现在已在主分支中添加了一个新提交,其中包括issue1分支中的所有提交。 您可以使用 git log 命令来验证修订历史记录中的新更改。

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life