首先,本地文件之前是svn管理,现在直接换成git,远程仓库已经有新代码和master分支
- 初始化 git init
- 关联远程仓库 git remote add origin https:....git(换成远程仓库地址)
- git branch -a 查看目前有哪些远程分支
- 拉取远程的master分支 git pull origin master ,此时报错 error: The following untracked working tree files would be overwritten by merge: 本地有多个文件与远程仓库不一致,不能直接使用 git reset --hard HEAD 因为目前还不在哪个分支
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.也不能直接使用切换分支 git checkout -b master origin/master
error: The following untracked working tree files would be overwritten by checkout:
.babelrc .js Aborting - 此时先贮藏目前的差异文件 git add . 添加全部差异文件;
$ git stash save -a 'svn'
You do not have the initial commit yet0@DESKTOP-2RBCSD9 MINGW64 /d/newFrontProject (master)
$ git commit
[master (root-commit) 9ddb6f8] nit svn (查看状态)$ git status
On branch master
nothing to commit, working tree clean -
再次查看git branch -a并且拉取$ git pull origin master,发现出现merge conflict;(master|REBASE 1/1)
$ git status
interactive rebase in progress; onto 1245feb -
查看所在分支会发现是rebase状态,也就不在master分支上 :
(master|REBASE 1/1)
$ git branch
* (no branch, rebasing master)
master0@DESKTOP-2RBCSD9 MINGW64 /d/newFrontProject/DossierSite/WebSiteForManager (master|REBASE 1/1)
$ git reset --hard HEAD(不想直接丢弃本地差异文件可以再次使用前面步骤5进行贮藏)
HEAD is now at 1245feb Merge #1 into master from dev1 -
使用rebase命令:(master|REBASE 1/1)
$ git rebase --continue
Successfully rebased and updated refs/heads/master. -
再次拉取master分支,此时状态正常,拉取成功:
(master)
$ git pull origin master --rebase
From https://
* branch master -> FETCH_HEAD
Already up to date. -
查看所在分支已正常:(master)
$ git branch
* master (*表示目前在这个分支上) -
此时直接git pull 拉取代码会提示没有关联远程分支:
(master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
-
使用命令:(master)
$ git branch --set-upstream-to=origin/master master
提示 Branch 'master' set up to track remote branch 'master' from 'origin'. -
使用 git pull正常,不需要指定分支
Already up to date.