Sri*_*ram 4 git version-control github
我有一个私人存储库github(例如“ProjectX”)。项目需求中途发生了变化,这意味着代码必须重写。我不想失去“ProjectX”上已经取得的进展,所以我做了以下事情:
git remote rm origin
还在 GitHub 上重命名了该项目。
git remote add origin git@github-user:user/ProjectX_advanced.git
这很成功。git remote -v在终端上 执行显示如下:
origin git@github-user:user/ProjectX_advanced.git (fetch)
origin git@github-user:user/ProjectX_advanced.git (push)
Run Code Online (Sandbox Code Playgroud)
我还可以将更改推送到上述存储库。
3. 在 github 上创建了一个名为“ProjectX”的新存储库。
4. 在我的本地存储库中创建了一个名为“ProjectX”的新项目。
5. 在其中初始化 git,如下所示:
6. 添加一个新的远程源,如下所示:
如果我现在在命令行上执行此操作,我将获得正确的远程位置。
7. 当我现在尝试将本地存储库中的更改推送到 github 存储库时,问题出现了:
看到的错误消息::
git init
git add .
git commit -m "First commit" .
git remote add origin git@github-user:user/ProjectX.gitgit remote -v
git push origin master
To git@github-user:user/ProjectX.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github-user:user/ProjectX.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
我在这里和这里看到了一些以前的问题以及其他一些问题,这些问题表明我需要进行git pull并合并才能推送这些更改。
我的问题:
1. 如果我执行 a git pull,我的新“ProjectX”将被我不需要的代码覆盖。我该如何解决它?
2. 我已重命名所有遥控器(输出git remote -v符合预期)。我是否错过了重命名某些遥控器?
3.我该如何解决这个问题?
小智 7
首先从github克隆代码
git clone https://github.com/emample_user/my_repo_project.git
Run Code Online (Sandbox Code Playgroud)
在那之后
如果要将my_repo_project更改为Repo_project
并推送代码以重命名存储库
$git remote set-url origin https://github.com/emample_user/Repo_project
$git add .
$git commit -m "message"
$git push -u origin master
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11139 次 |
| 最近记录: |