Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the advanced usage of git checkout in Git conflicts

Shulou Source: shulou.com Published: 2022-06-01 17:16:54 09月28日 Update

What is the advanced usage of git checkout in Git conflict? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Background

Git conflicts are usually caused by modifying the same file, which may be submitted to a remote warehouse or by the need to merge the file.

Solution method

Are you sure which warehouse file you need?

Git checkout-- theirs conflicted_file.txt # keeps the remote

Git checkout-- ours conflicted_file.txt # keeps the local

Then execute add and commit

Git add-A

Git commit-m "update conflict

Take a chestnut.

Get the files on the remote server, prompting a conflict that needs to be merged

# git cherry-pick FETCH_HEAD

* branch refs/changes/85/12385/3-> FETCH_HEAD

Error: 'cherry-pick' is not possible because you have unmerged files.

Hint: Fix them up in the work tree

Hint: and then use 'git add/rm' as

Hint: appropriate to mark resolution and make a commit

Hint: or use 'git commit-aura.

Fatal: cherry-pick failed

View the status of the current warehouse

# git status

Not currently on any branch.

You are currently cherry-picking commit 53e5374.

(fix conflicts and run "git cherry-pick-- continue")

(use "git cherry-pick-abort" to cancel the cherry-pick operation)

Unmerged paths:

(use "git add..." To mark resolution)

Both modified: file1.txt

Execute with the prompted command

# git cherry-pick-continue

U file1.txt

Error: 'commit' is not possible because you have unmerged files.

Hint: Fix them up in the work tree

Hint: and then use 'git add/rm' as

Hint: appropriate to mark resolution and make a commit

Hint: or use 'git commit-aura.

Fatal: Exiting because of an unresolved conflict.

Prompt that file1.txt has an update and make sure to replace the file with the remote warehouse. Theirs is used here

Git checkout-theirs file1.txt

Then add it to the local warehouse

Git add-A

Finally, continue cherry-pick "copy"

# git cherry-pick-continue

[detached HEAD 8f26ce8] Summary: test git checkout-theirs

Author: Rik

2 files changed, 0 insertions (+), 0 deletions (-)

Summary

There is a difference between git ckeckout and-- ours and-- theirs with parameters.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: File warehouse conflict prompt help advanced clear content reason parameter command summary that is article novice method more server status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux MySQL macOS Docker