Git
提交代码
-
提交代码第一步:git status 查看当前状态
当你忘记修改了哪些文件的时候可以使用 git status 来查看当前状态,
Changes not staged for commit: (use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: src/utils/hostinfo.js
modified: src/views/network/advance.vue
no changes added to commit (use "git add" and/or "git commit -a")
- 提交代码第二步:git add . 或者 git add xxx
- 提交代码第三步:git commit -m "提交的日志信息" 推送修改到本地git库中
- git pull <远程主机名> <远程分支名> 取回远程主机某个分支的更新,再与本地的指定分支合并
- 提交代码第五步:git push <远程主机名> <远程分支名> 把当前提交到git本地仓库的代码推送到远程主机的某个远程分之上
冲突解决
提交代码的时候 可能会发生代码冲突:
error: Your local changes to the following files would be overwritten by merge:
protected/config/xxxx.xxx
Please, commit your changes or stash them before you can merge.
解决办法:
git stash
git pull
git stash pop
然后可以使用git diff -w +文件名 来确认代码自动合并的情况
反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:
git reset --hard
git pull
其中git reset是针对版本,如果想针对文件回退本地修改,使用
git checkout HEAD file/to/restore