git 常用命令

 1. 配置

git config --list
git config --global http.sslverify false
git config --global user.name "Firstname Lastname"
git config --global user.email your_email@youremail.com

2. 文件状态

-> 查看文件改动

git status

注意,git status 不记录空的文件夹

-> 删除所有没有被 git 记录的文件和文件夹

git clean -fd

3. 查看提交日志 (commit, log, tag)

-> 查看所有提交的日志

git log

-> 查看第一条 log

git log -1

-> 查看某个文件的所有提交的日志

git log <file>

-> 查看某个提交 (commit) 的详细信息

git show <commit hash>

-> 查看某个 tag 信息

git show <tag>

-> 比较两个 commit 的差异

git diff <commit 1> <commit 2>

4. 分支 (branch)

-> 查看本地分支

git branch

-> 查看远程分支

git branch -r

-> 查看本地和远程所有分支

git branch -a

-> 创建一个本地分支 xxx

git branch <xxx>

-> 切换到分支 xxx

git checkout <xxx>

-> 删除本地分支 xxx

git branch -d <xxx>

-> push 本地分支到远程

git push origin xxx

-> 删除远程分支

git push --delete origin xxx

 5. Checkout 和 Pull, Push

-> Checkout 某个提交的版本

git checkout <commit>

-> Checkout 某个文件最新版本,这个操作将放弃本地对这个文件的修改

git checkout <file>

-> 更新在最新版本

git pull

-> 添加一个新的文件到 git

git add -N file

-> 查看远程的 hosts

git remote -v

-> 提交 commit

git commit -a -m "msg"

-> push commit 到远程服务器

git push

-> push branch foo 到远程服务器

git push origin foo

6. git stash

-> 保存本地的修改

git stash

-> List 本地保存的改动

git stash list

-> 应用本地 stash 里的修改到当前的 code

git stash pop stash@{0}

7. tag 和 release

-> 显示所有 tag

git tag

-> 显示 tag 1.4*

git tag -l '1.4*'

-> 显示某一个tag 信息

git show <tag>

-> 添加一个详细 tag, 名字是 v1.4,描述是 'my version 1.4'

git tag -a v1.4 -m 'my version 1.4'

-> push tag 到远程,成为一个 release

git push origin <tag>

 -> push 所有 tags 到远程

git push origin --tags

// BACKUP
git checkout Impala2.6-gcc4.9
git pull
git branch Impala2.6-gcc4.9_bak
git push origin Impala2.6-gcc4.9_bak:Impala2.6-gcc4.9_bak

// RESET on local
git checkout Impala2.6-gcc4.9
git pull
git log
git reset --hard 282cbfbca0f8c9f1aaa7a4a224e3c61aaa576c5c

// DELETE remote
git push origin :Impala2.6-gcc4.9

// Push to remote
git push origin Impala2.6-gcc4.9

create branch from another repository
git remote add <fork> <repo url>
git fetch <fork>
git checkout -b <main> <fork/master>
git push origin <main>

 

原文地址:https://www.cnblogs.com/weiweifeng/p/8125179.html