其他分享
首页 > 其他分享> > 常用的命令之 Git

常用的命令之 Git

作者:互联网

命令 描述
配置Git :
git config --global user.name uname 配置用户名
git config --global user.email email 配置用户邮箱
---
git remote add origin <url> 添加远程
git diff 文件差异
git statusgst 查看git状态
git add podfile 将 podfile 文件添加到暂存区
git add . 将所有的文件添加到暂存区
---
git commit -m 'message' 提交并填写信息
git commit -s 提交,并填写详细信息
git commit --amend 修改最后一次提交信息
git commit --amend --no-edit 修改最后一次提交,不用编辑信息
---
git log 查看log
git log -p
git log -p -2
---
git fetch 拉取代码(不常用)
git pull 等于 git fetch + git merge (常用,团队开发不推荐)
git pull --rebase 等于 git fetch + git rebase。(常用,团队开发时推荐)
git merge --abort 中断合并
---
git branch -a 查看所有的分支
git branch newMaster 创建新分支
git checkout newMaster 切换到新分支
git push origin newMaster 把新分支推送到远程
git branch -d newMaster 删除分支
git push origin --delete newMaster 删除远程分支
---
git checkout --conflict 合并冲突时,显示ours,theirs
git checkout --conflict=diff3 合并冲突时,显示ours,theirs,base
git config --global merge.conflictstyle diff3 设置默认的 conflictstyle 参数为diff3
---
git rebase 下面有 git rebasegit merge 的区别
git rebase --abort 终止 git rebase, 回到 rebase 之前的状态
git rebase --continue 合并冲突,要配合 git add 来使用
git rebase --skip 将引起冲突的 commit 丢弃,将自己提交的部分舍弃
git rebase -i 修改多个提交信息。修改后也要 git rebase --continue
git rebase -i HEAD~1 修改最近的1个提交信息,3可以修改为其他数字。
---
git tag 列出已有的标签
git tag -l 列出已有的标签
git tag -l "1.1*" 列出所有的1.1版本的标签
git tag -a 1.1.0 添加标签 1.1.0
git show 1.1.0 显示标签 1.1.0 信息
git push origin 1.0.0 将标签 1.0.0 推送到远程
git push origin tags 将所有的标签推送到远程
git tag -d 1.0.0 删除本地的标签 1.0.0
git push origin :refs/tags/1.0.0 删除远程的标签 1.0.0 (方法1)
git push origin --delete 1.0.0 删除远程的标签 1.0.0 (方法2)
---
git reset e4a0901 HEAD 回到 e4a0901,后续修改设为未暂存状态
git reset --mixed e4a0901 git reset e4a0901 效果一样
git reset --soft e4a0901 HEAD 回到 e4a0901,后续修改设为暂存状态
git reset --hard e4a0901 HEAD 回到 e4a0901,后续修改直接抛弃了。(危险!慎用!)

git rebasegit merge 的区别

☆ git rebase 操作流程
1. 取消并临时保存自己的提交
2. 将本地更新为最新状态
3. 把临时保存的提交合并上去


☆ git merget 操作流程
1. 拉取最新的状态,
2. 合并到自己的提交上生成新的提交。


☆ 案例解释说明:
如果某个 Git 已经存在 C1,C2 两个提交
A,B两个用户分别拉取在自己的本地。
A 提交 C3 于 9:00
A 提交 C4 于 11:00

B 提交 C5 于 10:00
B 提交 C6 于 12:00

A 推送代码到远程
B 拉取远程代码并推送到远程得到最近节点 C7

如果B采用 git merge 得到的提交顺序为:C1 ← C2 ← C3 ← C5 ← C4 ← C6 ← C7
如果B采用 git rebase 得到的提交顺序为:C1 ← C2 ← C3 ← C4 ← C5 ← C6 ← C7

git 的 三棵树

描述
HEAD 上一次提交
Index 预期的下一次提交
Work Directory 沙盒

git 的 状态

状态 HEAD 指向 Index 跟踪 Work Directory
已提交 上一次提交 上一次提交 上一次提交
未暂存 上一次提交 上一次提交 当前修改
已暂存 上一次提交 当前修改 当前修改

git reset 速查表

命令 HEAD 指向是否改变 Index 是否改变 Work Directory 是否改变 是否安全
git reset --soft [commit] YES NO No YES
git reset [commit] YES YES NO YES
git reset --hard [commit] YES YES YES NO

标签:reset,常用,Git,--,rebase,---,命令,git,提交
来源: https://www.cnblogs.com/dulinshun/p/chang-yong-de-ming-ling-zhi-git.html