美文网首页
git更换远程仓库地址-保持历史记录

git更换远程仓库地址-保持历史记录

作者: huyongming | 来源:发表于2021-01-21 10:14 被阅读0次

git更换远程仓库地址-保持历史记录的操作步骤

  1. codding上申请新的仓库,并初始化
  2. 本地更换远程仓库地址
git修改远程仓库地址 
方法有三种:
1.修改命令
git remote origin set-url [url]

2.先删后加(这种操作不会保持历史记录)
git remote rm origin
git remote add origin [url]

3.直接修改config文件(打开.git文件夹找到config文件,替换远程地址)
  1. 拉取远程代码
拉取远程代码会遇到冲突
Git :fatal: refusing to merge unrelated histories

解决办法:
使用命令行拉去代码:git pull origin master --allow-unrelated-histories

执行命令后会有一个提示提交注释的提示(vim编辑器)
# Please enter the commit message for your changes. Lines starting 
# with '#' will be ignored, and an empty message aborts the commit.

编写提交注释:
1. 在第一行输入理由:“更换远程仓库”,如果不是编辑模式可以按i键进入编辑模式
2. esc退出编辑模式
3. 输入“:w”保存输入
4. 输入“:q”退出

vim编辑器说明
1. Press i to enter insert mode.
2. Now you can type your message, as if you were in a normal (non-modal) text editor.
3. Press esc to go back to command mode.
4. Then type :w followed by enter to save.
5. Finally :q followed by enter to quit.

  1. 提交代码
git push -u origin master

相关文章

网友评论

      本文标题:git更换远程仓库地址-保持历史记录

      本文链接:https://www.haomeiwen.com/subject/umerzktx.html