配置用户名和邮箱
git config --global user.name "username"
git config --global user.email "username@example.com"
配置文本编辑器
git config --global core.editor vim
配置常用的别名
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
查看配置信息
git config user.name
git config --list
man git-branch
帮助
git help branch
git branch --help
初始化仓库
git init
克隆仓库
git clone git@github.com:mastercoder225/linux-command.git
git clone git@github.com:mastercoder225/linux-command.git linux-command-copy
跟踪新文件
git add new.txt
暂存已修改文件
git add modified.txt
标记冲突文件为已解决状态
git add conflict.txt
提交更新
git commit
git commit -m "fix"
git commit -a -m "fix"
移除文件
git rm remove.txt
git rm remove.txt -f
git rm remove.txt --cached
移动文件
git mv file.txt directory
重命名文件
git mv old.txt new.txt
取消文件暂存
git reset HEAD -- staged.txt
取消文件修改
git checkout -- modified.txt
查看远程仓库信息
git remote
git remote -v
git remote show origin
添加远程仓库
git remote add origin git@github.com:mastercoder225/linux-command.git
从远程仓库拉取信息
git fetch origin
推送分支到远程仓库
git push origin master
修改远程仓库引用名
git remote rename origin repo
移除远程仓库
git remote rm origin
创建新分支
git branch test
git checkout -b test
git checkout -b test origin/test
git checkout --track origin/test
切换分支
git checkout master
合并分支
git merge test
删除分支
git branch -d test
查看分支信息
git branch
git branch -v
git branch --merged
git branch --no-merged
查看远程分支信息
git ls-remote
git ls-remote origin
设置本地分支跟踪远程分支
git branch -u origin/test
查看本地分支跟踪信息
git branch -vv
变基
git rebase test
解决config
git rebase --abort 放弃rebase
//解决config
git rebase --continue //继续rebase
git push
删除分支
git branch -D mystudygit1.0 //强制本地删除
git push --delete origin xxxx //删除远程分支
返回历史版本
//使用git log命令查看所有的历史版本
git reset --hard 139dcfaa558e3276b30b6b2e5cbbb9c00bbdca96 //返回特定版本
网友评论