我平常进行git操作的顺序如下:
首先在vscode打开项目所在的文件夹
然后在VS Code的Terminal 中将该文件夹初始化为git仓库
git init
然后添加远程库
git remote add origin [email protected]:你的仓库名
建立完本地仓库与远程仓库连接,就可以开始推送。
我习惯使用rebase方式推送(merge与rebase的区别可见博主 ellenxx),推送流程为:
git add .git commit -m "feat: The change of this version."git pull origin master --rebasegit push origin master --force (首次推送建议 git push -u origin master --force)
但是我这次发现README写的有错别字,所以在远端README直接编辑修改了readme.md文件,然后想使用git pull origin master --rebase将其同步到本地,出现了冲突:fatal: It seems that there is already a rebase-merge directory, andI wonder if you are in the middle of another rebase. If that is thecase, please try rm -fr ".git/rebase-merge"and run me again. I am stopping in case you still have something
中间又去掉--rebase git pull origin master了一下 也出现一些错误,也记录一下:
git pull origin master
From gitee.com:funpony/learn-tex
* branch master -> FETCH_HEAD
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
然后参考git pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result._谁不小心的的博客-CSDN博客
如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fetch取得远程分支):
git reset --hard origin master
fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
HEAD is now at 2bc3331 update README.md.
然后重新使用git pull origin master --rebase之后提示如下:
From gitee.com:funpony/learn-tex
* branch master -> FETCH_HEAD
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr ".git/rebase-merge"
and run me again. I am stopping in case you still have something
valuable there.
然后根据提示git rebase --continue
git pull origin master --rebase
git rebase --continue
Successfully rebased and updated refs/heads/master.
便可继续git push origin master --force更新到本地,然后README就更新到本地了。
git push origin master --force
版权归原作者 沐小轲 所有, 如有侵权,请联系我们删除。