分支管理:
http://www.ruanyifeng.com/blog/2012/07/git.html
修改备份:
git stash
git stash apply
参考:http://www.cppblog.com/deercoder/archive/2011/11/13/160007.aspx
项目回滚:
1,将项目回滚到某个提交所在的版本(已经提交, 已push)
get reset --soft a31eb2beadb3479388958953e0cf6ba1f2d27883 //回滚到某个版本
git push origin dev -f //强制覆盖本地分支到远程
2,撤销某次提交(已提交, 已push)
git revert a31eb2beadb3479388958953e0cf6ba1f2d27883 //新建commit,用来撤销commit
分支删除:
git push origin :dev (注意冒号前有个空格!)
分支修改:
1,删除之前已经存在的pre分支,重新创建pre分支,将coupon分支内容复制一份到pre分支
git branch -D pre
(重新创建pre分支,将coupon分支内容复制一份到pre分支)
git pull -p
git checkout -b pre origin/pre
开发分支管理:
1,环境
①,生产环境 release分支
②,测试环境 develop分支
2,开发
每个开发人员自己从release分支上新建私有分支,修改完成后,先合并到develop分支发到测试环境测试,待测试环境测完后,再将私有分支直接合并到release分支,发布到线上环境
develop分支不允许合并到release分支
1,Git配置
2,生成密钥
3,将某次提交合并到指定分支
git cherry-pick <commit id>
git log -p <dev分支> //1-查看要合并的提交 git checkout master //2-切换到要合并的指定分支 git cherry-pick 62ecb //3-将提交合并到当前分支
4,忽略提交
git update-index --assume-unchanged FILENAME
5,将当前分支已经push后的内容回归到指定提交的版本
git reset --soft commit_id //1-回归到指定提交所在的版本
git push origin dev -f //2-强制将本地仓库推送到远程服务器
6,基本配置
git config --list
git config -e
git config -e --global
git config --global user.name "[name]"
git config --global user.email "[email]"
7,初始化提交
git init
git init [ProjectName]
git clone [Url]
git pull origin bp
git add [file] [file]
git commit [file] -m "[message]"
git pull origin bp
git push origin bp
8,分支
git push origin dev //创建分支
git checkout bp //切换分支到bp
9,状态和日志
git status //有变更的文件
git diff //工作区和暂存区的差异
git diff --cached [file] //暂存区和上一个commit差异
git diff HEAD //工作区和当前分支最新commit差异
git diff [first-branch]...[second-branch] //两次提交之间的差异
git log > log.txt //导出日志到文件
git log //当前分支的版本历史
git log --stat //提交历史
git log -p [file] //文件每次diff历史
git reflog //当前分支最近的提交
git log --follow [file] //文件的版本历史,包括改名
git whatchanged [file] //文件的版本历史,包括改名
git blame [file] //文件修改的人和时间
git reflog //当前分支最近的提交
git show [commit] //提交的元数据和内容的变化
git show --name-only [commit] //提交变化的文件
git show [commit]:[filename] //提交时的文件内容
10,远程仓库
git remote -v 显示所有远程仓库
git fetch [remote] 下载远程仓库所有变动
git remote show [remote] 显示远程仓库信息
git remote add [shortname] [url] 增加一个新的远程仓库
git pull [remote] [branch] 拉取远程仓库变化,并与本分支合并
git push [remote] [branch] 上传本地分支到远程仓库
git push [remote] --force (谨慎使用)即使有冲突,也强行推送当前分支到远程仓库
git push [remote] --all 推送所有分支到远程仓库
11,撤销
【Git撤销最全文档参考】
https://mp.weixin.qq.com/s?__biz=MzA4MjEyNTA5Mw==&mid=2652564939&idx=1&sn=ca3e5831a7a81287fdb20eba16d4ff4d&chksm=8464c581b3134c97e0f74112d9e26a29642c0ef6fa367a65d34f842a818791e416827442b4aa&mpshare=1&scene=1&srcid=0324TGRDlcs2oYZhcnaZuKnQ&pass_ticket=pbXKP35zSWRNGhdWHrYF4sclYrLGEi0Z8UhbDSGNAxVEbZyBIFT1BRc%2BBIK%2FhDON#rd
git checkout [file] 恢复暂存区文件到工作区:撤销git add
git checkout [commit] [file] 恢复本地仓库文件到工作区:撤销git commit
git checkout . (谨慎使用)恢复上一个commit所有文件到工作区:撤销git commit
git revert [commit] 新建commit,用来撤销commit,后者的变化将被前者抵消,并应用到当前分支
git reset [file] 重置暂存区文件和上一次commit一致
git reset --hard (谨慎使用)重置暂存区、工作区和上一次commit一致
git reset [commit] 重置当前分支指针为commit,同时重置暂存区,工作区不变
git reset --hard [commit] 重置当前分支的HEAD为commit,同时重置暂存区、工作区和commit一致
git reset --keep [commit] 重置当前HEAD为commit,但暂存区和工作区不变
git reset HEAD .
12,添加删除文件
git add [file] [file]
git add [dir] 目录
git add . 所有文件
git rm [file] [file] ... 删除工作区文件,将删除放入暂存区
git rm --cached [file] 停止追踪指定文件,文件会保留在工作区
git mv [original-file] [renamed-file] 文件改名,将改名放入暂存区
13,提交
git commit -m "[message]" 暂存区到仓库区
git commit [file] [file] -m "[message]" 暂存区到仓库区
git commit -a 提交工作区自上次commit之后变化到仓库区
git commit -v 提交显示所有diff信息
git commit --amend -m "[message]" 使用一次新的commit,替代上一次提交,如果代码没有改变,则用来改写上一次commit提交信息
git commit --amend [file] [file] ... 重做上一次commit,并包括文件的新变化
14,分支
git branch
git branch -r 远程
git branch -a
git branch [branch-name] 新建一个分支,但依然停留在当前分支 例如:git branch dev
git checkout -b [branch-name] 新建一个分支,并切换到新分支 例如:git checkout -b dev
git branch [branch-name] [commit] 新建一个分支,指向一个commit
git branch --track [branch-name] [remote-branch] 新建一个分支,并和一个远程分支建立追踪关系
git checkout [branch-name] 切换到指定分区,并更新工作区
git branch --set-upstream [branch] [remote-branch] 建立追踪关系,在现有分支和远程分支之间
git merge [branch] 合并指定分支到当前分支
git cherry-pick [commit] 将commit合并进当前分支
git branch -d [branch-name] 删除分支
git push origin --delete [branch-name] 删除远程分支
git branch -dr [remote/branch] 删除远程分支
15,其他
git archive 生成可供发布的压缩包
16,git文件名大小写修改
git mv --force Weixin.xml weixin.xml (在本地修改完提交不起作用,可以尝试在git服务器修改,然后下载)
git mv -f Weixin.xml weixin.xml
或者
Add ignorecase = false to [core] in .git/config;
17,标签
git tag 列出所有tag
git tag [tag] 新建一个tag,在当前commit
git tag [tag] [commit] 新建tag在指定commit
git show [tag] 查看tag信息
git push [remote] [tag] 提交指定tag
git push [remote] --tags 提交所有tag
git chekout -b [branch] [tag] 新建分支指向tag