Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Command Line 中使用 Git
  7. 制造冲突
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

制造冲突

当出现冲突时,您需要解决冲突,以完成您的工作。在这个步骤中,我们将使用我们现有的两个存储库故意制造冲突,“tutorial“和”tutorial2”。

首先,打开tutorial目录中的sample.txt文件。将下面的粗体文本添加到文件中,并提交更改,但暂时不要推送。

Anyone can learn Git with this tutorial and Backlog


add: Register a change in an index commit: Save the status of an index

$ git add sample.txt
$ git commit -m "append description of the commit command"
  [main 95f15c9] append description of the commit command
    1 files changed, 1 insertions(+), 0 deletions(-)

接着,打开tutorial2目录中的sample.txt文件。将下面的粗体文本添加到文件中并提交。

Anyone can learn Git with this tutorial and Backlog


add: Register a change in an index pull: Obtain the content of the remote repository

$ git add sample.txt
$ git commit -m "append description of the pull command"
  [main 4c01823] append description of the pull command
    1 files changed, 1 insertions(+), 0 deletions(-)

现在使用 git push 命令tutorial2中的修改推送到远程存储库。

$ git push
  Username: <username>
  Password: <password>
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (3/3), 391 bytes, done.
  Total 3 (delta 0), reused 0 (delta 0)
  To https://example.backlog.com/git/BLGGIT/tutorial.git
      3da09c1..4c01823  main -> main

在我们当前的远程存储库中,sample.txt文件包含第三行pull: Obtain the content of the remote repository,并且已经提交到历史日志中。

接下来,我们将把提交从我们的tutorial存储库推送到远程存储库。

$ git push
  Username: <username>
  Password: <password>
  To https://example.backlog.com/git/BLGGIT/tutorial.git
  ! [rejected]        main -> main (non-fast-forward)
  error: failed to push some refs to 'https://example.backlog.com/git/BLGGIT/tutorial.git'
  To prevent you from losing history, non-fast-forward updates were rejected
  Merge the remote changes (e.g. 'git pull') before pushing again.  See the
  'Note about fast-forwards' section of 'git push --help' for details.

如您所见,Git 引发了冲突并拒绝了您的推送。

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life