Git: currently in merge/conflict with private remote repo. How to tell Git to just use my local files?
尝试在个人项目中使用/学习Git。只有我和一个远程git repo,几个提交,我陷入了一个失败的合并中。我的很多文件现在也有git合并冲突标记。
我该怎么告诉Git把所有的东西都扔掉,用我的?
我是如何进入状态的具体示例:
1 2 3 4 5 6 7 8 9 10 | echo A new file > myFile.txt # example file git add myFile.txt # add file git commit # commit changes git push # push changes to remote repo echo A conflicting edit > myFile.txt # oh, no, forgot some changes git add myFile.txt # add again git commit --amend # amend previous commit git push # fails. Git suggests to do a pull first git pull origin HEAD #"Automatic merge failed" Now what? # Just use what I have locally! |
1 2 3 | git checkout --ours . # checkout our local version of all files git add -u # mark all conflicted files as merged/resolved git commit # commit the merge |
号
有一个混乱的选择,可以打破回购为其他所有人使用相同的远程来源。只有当你是唯一一个使用它的人时才考虑它:
1 2 | git reset --hard HEAD # undo that failed merge git push --force # replace everything remote with local |
解释(现在我更了解
您的GUI可能只是设置了
您的另一个选择是使用
文档
您可以使用以下演示shell脚本看到两种不同的工作样式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/bin/sh mkdir gittest cd gittest git init git checkout master echo"Line one"> bar git add bar git commit -m"Original commit" git checkout -b fork1 echo"Line one and something"> bar echo"Line two"> bam git add bar bam git commit -m"Fork1 commit." git checkout master git checkout -b fork2 echo"Line one and other stuff"> bar echo"Line three"> baz git add bar baz git commit -m"Fork2 commit." git checkout fork1 if ["$1" ="ours" ]; then # `ls gittest` => bam bar # `cat gittest/bar` => Line one and something git merge -s ours fork2 else # `ls gittest` => bam bar baz # `cat gittest/bar` => Line one and something git merge -X ours fork2 fi |