回退
文件或文件夹
git checkout <hash> <filename or foldername>
仓库软回滚
软回滚: 文件内容回退,但整体commit记录继续新增)
# history-commit-id 要回滚到的commit-id
# current-commit-id 最新的commit-id
git reset --hard 回滚到的id
git reset 当前id
git add .
git commit -m "xxxxx"
git push
在指定文件夹下设置提交用户名和邮箱
# 查看Git配置
git config --list
git config user.name xxxx
git config user.email xxxx@163.com
# 是否设置成功
git config --list
文件的更改关联的commitid
commitid 关联的文件修改
获取远程代码的更新
git fetch
git pull
git fetch vs git pull
branch操作
命令 | 描述 | zsh |
---|---|---|
git checkout <branch> <finder/file> |
从其他分支copy文件/文件夹 | |
git branch -m <oldname> <newname> |
修改:本地分支名称 | |
git branch --set-upstream-to=<origin/test> <test> |
指定分支的upstream | |
git remote rename <oldname> <newname> |
修改:远程分支名称 | |
git checkout -b <branchname> |
以当前分支为副本, 创建并切换到新分支 | |
git branch -D <branch-name> |
删除:本地分支 | gb -D <branch-name> |
git push origin --delete branch |
删除:远程分支 | |
git checkout -b <branch> <origin/branch> |
以远程分支 为副本,在本地新建分支(不以本地分支目录为副本) |
gcb <branch> <origin/branch> |
复制其他分支的文件夹或文件
git checkout [分支名称] -- 路径
git checkout origin/test -- aa/bb/aa.js
单独拉取一个commit记录
git cherry-pick -x [commit的id]
zsh 配置
vim ~/.zshrc
source ~/.zshrc
常用plugins:
plugins=( git git-flow git-flow-completion )
查看git配置
git config --list 或
cat .git/config 或
gcf
fork后与原仓库同步
新增remote(远程上游仓库)
git remote add upstream <remote-url>
git fetch upstream
git log
glol(每条记录信息最详细)和glg(展示多条记录)配合使用
glog | git log --oneline --decorate --color --graph
glg | git log --stat --color
信息比较详细,每次展示的少,显示完整的commitID,提交人(邮箱),修改的文件,修改的文件数量等,算是最详细的了`
glol | git log --graph --pretty = format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
/显示分支名称,commit文字,commitID,时间,提交人/`