git 基本操作

git配置

[plain]  view plain  copy
 
  1. git config --global user.name my_name  
  2. git config --global user.email my_email  
  3. git config --global credential.helper store  


远程仓库的添加与删除

[plain]  view plain  copy
 
  1. git remote add origin ****  
  2. git remote -v  
  3. git remote show origin  
  4. git remote show  
  5. git remote rename  origin test  
  6. git remote rm origin  

创建一个git仓库

[plain]  view plain  copy
 
  1. git init  
  2. git clone ***  


创建分支

[plain]  view plain  copy
 
  1. git branch test  
  2. git checkout -b test  
  3. git checkout -b test origin/test  
  4. git checkout --track origin/test  


追踪远程分支

[plain]  view plain  copy
 
  1. git branch -u origin/test test  


删除分支

[plain]  view plain  copy
 
  1. git branch -d test  
  2. git push --delete origin devel  
  3. git fetch -p  

重命名分支

[plain]  view plain  copy
 
  1. # git branch -m test other  

暂存修改

[plain]  view plain  copy
 
  1. git add 1.txt  
  2. git reset HEAD 1.txt  
  3. git checkout -- 1.txt  


删除文件

[plain]  view plain  copy
 
  1. git rm 1.txt  
  2. git rm -f 1.txt  
  3. git rm --cached 1.txt  

重命名文件

[plain]  view plain  copy
 
  1. git mv 1.txt 2.txt  

差异比较

[plain]  view plain  copy
 
  1. git diff  
  2. git diff --staged  
  3. git diff HEAD  
  4. git diff HEAD~2 HEAD  
  5. gid diff master  

提交

[plain]  view plain  copy
 
  1. git commit -a -m "init"  

修改提交

[html]  view plain  copy
 
  1. git commit --amend  
  2. git rebase -i HEAD~3  
  3. git reset  
  4. git revert  


分支合并

[html]  view plain  copy
 
  1. git merge test  
  2. git rebase master test  
  3. git cherry-pick C1 C2  


获取远程仓库内容

[plain]  view plain  copy
 
  1. git fetch  

推送到远程仓库

[html]  view plain  copy
 
  1. git push origin test  

从远程仓库拉取

[plain]  view plain  copy
 
  1. git pull origin test  

打标签

[plain]  view plain  copy
 
  1. git tag v1.0 C1  


删除标签

[plain]  view plain  copy
 
  1. git tag -d v1.0  
  2. git push origin --delete tag v1.0  

标签推送到远程

[plain]  view plain  copy
 
  1. git push --tags  

获取远程标签

[plain]  view plain  copy
 
  1. git fetch origin tag v1.0  

查看提交历史

[plain]  view plain  copy
 
  1. git log  
  2. git log -p -2 // 显示每次提交的内容差异  
  3. git log --stat // 仅显示简要的增改行数统计  
  4. git log --pretty=oneline  
  5. git log --oneline  
  6. git log --pretty=format:"%h %an %s" // 显示每次提交的简短哈希字串 作者的名字 提交说明  
  7. git log --pretty=format:"%h %s" --graph // 以图形化的方式显示  
  8. git log --author=name --since="2008-10-01" --before="2008-11-01" --no-merges -- t/  
  9. gitk // 启动图形化工具  

储藏

[plain]  view plain  copy
 
  1. git stash  
  2. git stash save "this is a stash"  
  3. git stash list  
  4. git stash apply  
  5. git stash apply --index stash@{0}  
  6. git stash drop stash@{0}  
  7. git stash pop --index stash@{0} // 应用并直接删除第一个储藏  
  8. git stash show -p | git apply -R // 取消应用储藏  
  9. git stash branch test stash@{0} // 基于储藏创建分支 test  
  10. git stash clear  

你可能感兴趣的:(git 基本操作)