workspace:工作区
staging area:暂存区/缓存区
local repository:版本库或本地仓库
remote repository:远程仓库
- git config
git config -global user.name "[name]"
git config -global user.email "[email adderss]"
- git init, 用于创建一个新的代码库。
git init [repository name]
- git clone, 通过指定的URL获取一个代码库到本地
git colne https://gitee.com/qingqingdan/caigit.git
- git status, 检查文件状态
- git add , 将文件添加至暂存区
# 将某个指定文件添加至暂存区
git add [filename]
# 将所有文件添加至暂存区
git add .
- git commit , 提交更新
git commit -m "本次提交说明"
- git push,推送到远程仓库
git push origin [分支名]
git push origin master
- 查看提交已暂存和未暂存的修改
git diff
- 查看提交历史
git log
- 从暂存区中取消文件
git reset head <file>
- 回退到指定版本
# git checkout [版本号]
- 查看分支
- 切换分支
- 创建分支
git branch [分支名]
- 删除分支
git branch -d [分支名]
- 查看分支
git branch
git branch -v, 查看每一个分支的最后一次提交。
- 合并代码,将master分支合并到gh-pages分支
- 使用 reflog 恢复删除的文件
例如,之前合并操作删除了项目中的文件‘zz.txt’,现在想要恢复。
git reflog 记录了 Git 的所有操作,包括每次提交、合并、重置等,
我们可以通过在 reflog 中找到误删除文件的 SHA1 版本号,然后使用以下命令进行恢复
git checkout HEAD@{ commit-hash} [fileName]
- 拉取指定分支的代码
git clone -b branch_name repository_url
例如,拉取wechat分支的代码
21. megre代码
比如要将A分支上的代码合并到B分支上,
#先切换到 B分支
git checkout B
# megre A分支上的代码
git merge A
#将megre A分支上的代码,提交到B分支上去
git push origin B
- commit后,但没有push,撤销本次commit并清除提交历史记录
git reset --hard HEAD^