# 命令
示意 | git 命令 |
---|---|
使用 git 对文件初始化 | git init |
告诉 git ,你要对哪些文件进行存档操作,将对应的文件添加到对应的暂存区 | git add <file> , 示例: git add test.txt |
添加的暂存区之后让 master 管理员,帮我们做个存档,生成一个存档记录 | git commit -m <message> ,示例 git commit -m 实现了网站登录功能 |
有多个存档记录的时候,在各个记录存档之间切换 | git reset —hard commit_id ,commit_id 是对应的存档记录 |
git 帮你召唤一个名叫 fixbug 的新档案管理员 | git checkout -b <name> 或者 git switch -c <name> ,示例: git checkout -b fixbug 「创建 + 切换分支」 |
切换到新的分支 fixbug | git checkout <name> 或者 git switch <name> ,示例: git checkout fixbug |
切换回 master 分支,然后把 develop 分支合并起来 | git checkout master``git merge develop |
在 develop 分支开发新功能,发现我的网站上有个 bug,切换到 master 分支,然后在 master 分支新建一个 bugfix 的分支 | git checkout master``git checkout -b bugfix |
修复完 bug,切换回 master 分支,再把 bugfix 分支合并过来 | git checkout master |
git merge bugfix |
# 常用的 git 命令
git clone <[email protected]>:xxxx
,下载仓库git init
,初始化本地仓库 .gitgit status -sb
,显示当前所有文件的状态git add 文件路径
,用来将变动加到暂存区git commit -m "信息"
,用来正式提交变动,提交至 .git 仓库- 如果有新的变动,我们只需要依次执行 git add xxx 和 git commit -m 'xxx' 两个命令即可。先 add 再 commit,行了,你学会 git 了。
git log
查看变更历史git pull
取回远程主机某个分支的更新,再与本地的指定分支合并- 查看分支:
git branch
- 创建分支:
git branch <name>
- 切换分支:
git checkout <name>
或者git switch <name>
- 创建 + 切换分支:
git checkout -b <name>
或者git switch -c <name>
- 合并某分支到当前分支:
git merge <name>
- 删除分支:
git branch -d <name>
-- 其余待补充 --