当本地的分支和网页上的分支有区别的时候,我希望将本地的版本上传,同时删除远程的版本。
在政别人对我的代码提出修改意见之后,我在网页端进行了一些修改,然后又回到本地进行修改。修改之后我希望将本地的版本传上去
$ git push origin feature/downloader
To https://gitlab.com/xxxx/xxx.git
! [rejected] feature/downloader -> feature/downloader (fetch first)
error: failed to push some refs to 'https://gitlab.com//xxxx/xxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这个报错告诉我们,这个分支的push请求被拒绝了,原因是远程主机上的对应分支内容也有改动。我们应该这么做
- 首先
git pull origin feature/downloader
,提示信息告诉你,现在又两个版本,branch和88bb260..cd98cf0,这两个版本的data_uri.py文件不能自动合并,有冲突。我们也可以使用```git status···查看两者的区别。
Unpacking objects: 100% (6/6), done.
From https://gitlab.com//xxxx/xxx.git
* branch feature/downloader -> FETCH_HEAD
88bb260..cd98cf0 feature/downloader -> origin/feature/downloader
Auto-merging api/handlers/api/data_uri.py
CONFLICT (content): Merge conflict in api/handlers/api/data_uri.py
Automatic merge failed; fix conflicts and then commit the result.
如果使用pycharm打开有冲突的文件,会发现文件变成这个样子
<<<<<<< HEAD
class DataURI:
def __init__(self, url_or_data):
self.url_or_data = url_or_data
...
=======
async def request_url(self):
downloader_url = self.downloader_url()
timeout = aiohttp.ClientTimeout(total=5)
async with aiohttp.ClientSession(timeout=timeout) as
...
>>>>>>> cd98cf016c457f96df42c6bb390d7e21834dda43
这个表示有冲突的地方。当然也可以使用git show cd98cf016c457f96df42c6bb390d7e21834dda43
查看有区别的地方。
- 在修改了冲突之后,我们可以使用
git add .
将修改添加,然后使用git commit
提交修改。 - 使用
git push origin feature/downloader
提交修改
网友评论