项目现在是多人协同开发,git代码管理,容易有冲突
先来一个git pull,发现不能拉取代码,错误信息
emote: Counting objects: 154, done.
remote: Compressing objects: 100% (95/95), done.
remote: Total 154 (delta 91), reused 89 (delta 54)
Receiving objects: 100% (154/154), 24.39 KiB | 4.07 MiB/s, done.
Resolving deltas: 100% (91/91), completed with 9 local objects.
From http://ip.ip.ip.ip/***/***
f587290..f9d88fc develop -> origin/develop
Updating f587290..f9d88fc
error: Your local changes to the following files would be overwritten by merge:
src/api/host.js
src/api/index.js
Please commit your changes or stash them before you merge.
Aborting
肯定不会陌生的了
那我就按照它的提示,先commit一下吧!git commit -m "test"
然后又是预期的一样,不能commit,错误信息
On branch develop
Your branch is behind 'origin/develop' by 23 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
modified: src/api/host.js
modified: src/api/index.js
no changes added to commit
它现在又叫我git pull了,有点晕晕的~
我看到了个词 stage,有点眼熟,运行命令看看帮助 git stage -help
好像没有我想要的
然后不小心打成了 git stash 命令
我写的代码不见了!心有点慌!怎么办呢?
查了下万能的百度,说是把我的文件保存起来了,想恢复用 git stash apply 命令。
我就放下心了,试了下,真的可以恢复!好神奇。
git stash 之后没提交的代码就不见了,去了另一个地方,这时我就可以 git pull 了!随心所欲拉代码!
拉完代码再git stash apply 把代码恢复好,这时需要解决冲突
Auto-merging src/api/index.js
CONFLICT (content): Merge conflict in src/api/index.js
Auto-merging src/api/host.js
CONFLICT (content): Merge conflict in src/api/host.js
这时运行git commit -m "test" 还是报错
U src/api/host.js
U src/api/index.js
error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
根据它的提示,解决完冲突,要使用git add file
那我就用了两行命令
git add src/api/host.js
git add src/api/index.js
不太明白这两行有什么用,加到哪里去啊?
不管了,运行git commit -m "test"
[develop cabfc86] test
2 files changed, 52 insertions(+), 1 deletion(-)
大功告成!成功提交了代码,开心~