gpt4 book ai didi

Git:目前与私有(private)远程仓库 merge/冲突。如何告诉 Git 只使用我的本地文件?

转载 作者:IT王子 更新时间:2023-10-29 00:41:19 24 4
gpt4 key购买 nike

尝试在个人项目中使用/学习 git。只有我和一个远程 git 存储库,一些提交,我陷入了失败的 merge 。我的很多文件现在也有 Git merge 冲突标记。

我如何告诉 git 把所有东西都扔掉,只用我的?

我如何进入我所处状态的具体示例:

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!

最佳答案

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

有一个困惑的替代方案可以破坏使用相同远程源的其他所有人的 repo 协议(protocol)。仅当您是唯一使用它的人时才考虑它:

git reset --hard HEAD # undo that failed merge
git push --force # replace everything remote with local

解释(现在我对 git 的理解更好了)
发生这种情况的原因是因为修改提交会改变“历史”。在本地执行此操作是安全的,因为它不会影响其他任何人。但是,修改已推送的提交确实会影响其他存储库,并且不安全。

关于Git:目前与私有(private)远程仓库 merge/冲突。如何告诉 Git 只使用我的本地文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12632666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com