一. git版本回退方法
git reset --hard HEAD //# 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
git add . //添加到暂存区
git commit ‘roll-back’ //提交到仓库区
git push -f origin master //强制推到 master仓库 (很危险,会导致某些中间版本记录消失,本地用用还可以,线上慎用)
其实在推送时,尽量避免git push -f
的操作,或者说git push -f
是一个需要谨慎的操作,它是将本地历史覆盖到远端仓库的行为。
当然也并非禁止,有时,如果代码组内review后,确认代码正确无误,保证大家未pull的情况下,强制推送后,可以保持目录树清洁。
二.使用Git下载指定分支
命令为: git clone -b 分支名 仓库地址
使用Git下载master分支代码,使用命令:git clone -b master https://git.oschina.net/oschina/android-app.git
三.git 提交文件
一次 add 多个文件的方法 git add file_1 file_2 file_3 多个文件用 空格 隔开
git 提交 文件夹的方法 git add catalog_name
扫描二维码关注公众号,回复:
5036943 查看本文章
修改或添加了多个文件,但只想提交部分代码的正确方式:
git add config/esqueryconfig.php //提交到暂存区
git stash -u -k //忽略其他,关键一步
git status //可以看到只有一个文件需要commit
git commit -m 'es升级配置文件' //提交暂存区
git pull //拉去合并
git push //推到远端仓库