Git
git文件状态的生命周期:
untracked: 未追踪
unmodified: 未修改
mofified: 已修改
staged: 已暂存
git常用术语:
HEAD 表示当前版本
HEAD^ 表示上一个版本,n个^表示上n个版本
HEAD~n 表示上n个版本
git常用命令:
$ git config --global user.name <name>
设置用户名
$ git config --global user.email <email>
设置电子邮件地址
$ git config --list
查看配置信息
$ git init
初始化当前文件夹为git项目目录
$ git status
git status -s 以简洁模式查看
$ git commit -am <description>
等价于 git add . + git commit -m <description>
多行注释提交使用单引号:git commit –m ''
$ git log
查看日志记录
--before 显示指定日期之前的commit
git log --before="2020-07-18 16:05:00"
--after 显示指定日期之后的commit
git log --after="2020-07-18 16:05:00"
--oneline 以行的形式简洁输出
git log --oneline
--graph 图形形式可以查看分支情况
-- filename 查看指定文件的修改历史
git log --oneline -- utill.c
$ git show
git show commit_id 查看指定commit的修改
git show -- filename 查看指定文件的修改历史
git show dcf6b8fa055c9c8897662b31c8ec6f2a9bb9eca5 -- util.c
$ git reflog
查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作)
git log则不能查看已经删除了的commit记录(git reset --hard <版本号>会删除 commit 记录)
$ git branch
git barnch -r 查看远程分支
git barnch -a 查看所有分支
git branch <branch_name> 创建新分支
git branch -d <branch_name> 删除分支
$ git remote
git remote -v 列出远程分支的详细信息
$ git push
git push -f 强制推送
git push <remote> 将当前分支推送到远程主机的对应分支
git push <remote> <local> 将本地分支推送到远程主机相应分支,如果远程相应的分支不存在则创建
git push <remote> --delete <branch> 删除指定的远程分支
$ git fetch
git fetch 更新所有分支
git fetch <remote> <branch> 取回远程分支的内容,本地主机上要用"remote/branch"的形式读取
$ git merge <dev>
将分支dev合并到当前分支中,自动进行新的提交
--no-commit 不自动进行新的提交
$ git pull = git fetch + git merge
$ git rebase
git rebase 与 git merge 区别
在rebase的过程中,也许会出现冲突(conflict). 在这种情况,Git会停止rebase并会让你去解决冲突;在解决完冲突后,用"git-add"命令去更新这些内容的索引, 然后你无需执行 git-commit, 只要执行:
git rebase --continue # 继续rebase
git rebase --abort # 放弃rebase
git rebase -i <commit_id>
使用git rebase -i命令可以对<commit_id>之前的多个commit结点进行编辑,如下: