Git使用技巧

/ 0评 / 0

配置全局用户名密码

git config --global user.name "name"

git config --global user.email "email"

也可以直接 vim ~/.gitconfig 编辑这个文件

git init 初始化 git 目录

git add 添加文件到缓存区

git commit -m "提交注释信息" 提交更改的文件

git push 推送到远程

git pull 拉取到本地

git status 目录中文件状态

git log 描述我们之前的提交

git reset --hard 某次提交的hash值 重置到某次提交
git reset --soft 某次提交的hash值 重置到某次提交(不影响代码)

.gitignore 忽略配置文件,这里面添加的文件或者文件夹都不会被添加

git rm -rf --cached .idea/ 删除没有提交的缓存区中的ide配置文件

git branch 添加分支/显示分支

git branch -d 删除分支

git checkout 检出分支

git checkout -b 创建并检出分支

git merge 分支名 将某个分支合并到当前分支

git diff 显示冲突位置

git config --global alias.s status 配置快捷方式,此处将status的快捷方式定为 s

git config --global --unset alias.s 去除配置项

vim ~/.zshrc(zshell的配置文件) 打开配置文件 可以直接配置快捷方式,比如 找到 alias 的位置,添加 alias gs="git status",那么gs就等价于git status了

git stash 加入缓存区

git stash list 缓存区列表

git stash apply 取出某个缓存

git stash pop 取出某个缓存并将其从缓存区删除

git stash drop 删除缓存区的东西

git remote add origin 添加远程仓库路径

git push -u origin master 推送到远程分支

git rebase 变基

评论已关闭。