主要使用命令:
git clone [path]#克隆远程分支到本地
git status #查看当前仓库的状态
git add [fileName]# 将工作区的修改提交到暂存区
git add .# 将工作区的修改全部提交到暂存区
git commit # 将暂存区的修改提交到当前分支
git pull # 从远程更新代码
如出现如下错误:
error: Your local changes to the following files would be overwritten by merge:
core/src/main/resources/profiles/dev/config.properties
core/src/main/resources/spring/applicationContext.xml
Please commit your changes or stash them before you merge.
Aborting
解决方法
通过git stash将工作区恢复到上次提交的内容,同时备份本地所做的修改,之后就可以正常git pull了,git pull完成后,执行git stash pop将之前本地做的修改应用到当前工作区。
git stash
git pull
git stash pop
备注:
git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。
git pull:拉取服务器上的代码;
git stash pop: 从Git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个Stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。
git stash list: 显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。
git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现,原来stash的哪些节点都消失了。
查看缓存本地集合
导入本地缓存
git push # 将本地代码更新到远程分支上
git reset # 回退到某一个版本
git branch -a #查看所有分支
git checkout --[fileName] #撤回本地修改文件
git checkout . #撤回本地所有修改文件
git checkout -b dev(本地分支名) origin/dev(远程分支名)
基本提交操作步骤:
1.查看状态
2.添加操作
git add //添加到暂存区(stage)
git add . //全部提交到暂存区
复制状态下的需要提交内容的路径,然后使用:git add 路径 添加
如图:
3.查看添加后的状态
git status
4.提交操作
git commit -m"本次提交描述"
5.推送到远程
git push