linux git 操作
branch 操作
新建分支new_branch同步远程分支origin/xxx
git checkout -b 新分支名 origin/远程分支名
新分支同步到远程仓库
git push origin 新分支名
查看本地分支
git branch
查看远程分支
git branch -r
查看所有分支
git branch -a
拉取远程分支(如果不是origin,则需要换成对应的名称)
git remote update origin --prune
切换分支(不需要 origin)
git checkout 分支名
拉取当前分支代码
git pull origin 分支名
删除本地分支
git branch -d 分支名
删除远程分支
git push origin --delete 分支名
提交操作
将修改文件提交到暂缓区
git add 文件名
提交修改
git commit -m “First commit”
推送到远程库
git push origin maste
查看本地修改
git status
如果在远程服务器上有代码更新,直接丢弃所有更改的命令
git checkout ./
回滚提交(将当前branch的HEAD指针指向commit hash)
git reset --hard resetVersionHash
查询git提交版本的hash
git rev-list --max-count=2 HEAD
查询当前提交版本的hash
git rev-parse HEAD
分支合并
合并 分支 到本地分支
git merge 分支名
查看合并状态 并解决冲突
git status
将冲突文件提交至 暂缓区
git add 冲突文件
提交merge 后的结果
git commit -m “merge commit”
推送合并结果到远程库
git push origin 分支名
问题解决
git 冲突解决
needs merge error: you need to resolve your current index first
解决方案:本地回退到当前版本,不影响远程库
git reset --hard