您好,登錄后才能下訂單哦!
Git沖突中g(shù)it checkout高級(jí)用法是什么,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
Git沖突的原因,一般是修改了同一個(gè)文件導(dǎo)致的,這個(gè)文件有可能是別人提交到遠(yuǎn)程倉庫里面,還有就是需要合并這個(gè)文件導(dǎo)致的。
你確定你需要的是哪個(gè)倉庫的文件
git checkout --theirs conflicted_file.txt # 保留遠(yuǎn)端的
git checkout --ours conflicted_file.txt # 保留本地的
然后執(zhí)行add和commit
git add -A
git commit -m "update conflict
獲取遠(yuǎn)端服務(wù)器上的文件,提示沖突了需要合并
# 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 <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: cherry-pick failed
查看當(dāng)前倉庫的狀態(tài)
# 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 <file>..." to mark resolution)
both modified: file1.txt
用提示的命令執(zhí)行
# 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 <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
提示file1.txt有更新,確定替換為遠(yuǎn)程倉庫的文件。這里用theirs
git checkout --theirs file1.txt
然后添加到本地倉庫
git add -A
最后繼續(xù)cherry-pick「復(fù)制」
# git cherry-pick --continue
[detached HEAD 8f26ce8] Summary : test git checkout --theirs
Author: Rik
2 files changed, 0 insertions(+), 0 deletions(-)
git ckeckout 和 帶參數(shù)的--ours和 --theirs還是有區(qū)別的。
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。