# 常用命令
# 创建分支
git checkout -b newname
# 提交分支
git push origin newname: newname
# pull分支
git pull origin newname
# push分支
git push origin newname
# 切换分支
git checkout brancename
# 查看分支
git branch -a
# 删除本地分支
git branch -d branch-name
# 删除远程分支
git branch -r -d origin/branch-name 有问题
# 首次提交分支
git push --set-upstream origin temp
# 回滚版本(soft)
git reset --soft HEAD^
# 项目初始化
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://git.oschina.net/path.git
git push -u origin master
# 从https转成ssh
git remote rm origin
git remote add origin "Git仓库的ssh格式地址"
git push --set-upstream origin master
# 合并分支上的单个commit
git cherry-pick 62ecb3
然后再使用git push --force将本次变更强行推送至服务器
# 移除某个文件夹的版本控制
git rm -r -n --cached "bin/" //-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
git rm -r --cached "bin/" //最终执行命令.
git commit -m" remove bin folder all file out of control" //提交
git push origin master //提交到远程服务器
# 修改远程url
- 修改命令
git remote set-url origin [url]
例如:git remote set-url origin gitlab@gitlab.chumob.com:php/hasoffer.git
- 先删后加
git remote rm origin
git remote add origin [url]
- 直接修改config文件
SVN和git同时存在处理
svn checkout新目录
git clone --no-checkout gitpath tmp
mv tmp/.git .
rmdir tmp
git reset --hard HEAD
# 放弃本地修改,强制同步远程
git fetch --all
git reset --hard origin/master // 远程分支名称
git fetch
常见问题 →