Git命令小结

2018-08-22  本文已影响11人  Colleny_Z

名词解释

功能命令

一、新建代码库

  git init
 git init [project- name]
 git clone [url]

二、配置
Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。

 git config --list
 git config -e [--global]
git config [--global] user.name "[name ]"
git config [--global] user.email "[email address]"

三、增加/删除/修改文件

    git  status
    git diff
    git  add  [file1]   [file2] ...
   git  add  [dir]
   git  add .
  git  add  -p
  git rm  [file1] [file2] ...
   git rm --cached  [file]
   git mv [file- original] [file "ename"]

四、代码提交

git commit -m [message]
git commit  [file1] [file2]  ... -m [message]
git commit -a
git commit -v
git commit --amend -m [message]
git commit --amend [file1]  [file2]

五、分支

   git branch
   git branch -r
    git branch -a
    git branch [branch-name]
    git branch --track [branch] [remote-branch]
  git branch -d [branch-name]
  git push origin --delete [branch-name]
  git branch -dr [remote/branch]
  git checkout -b [branch]
  git checkout [branch-name]
  git checkout -
   git branch --set-upstream [branch] [remote- branch]
  git merge [branch]
  git rebase <branch>
   git cherry-pick [commit]

六、标签

 git tag
git tag <tagname>
git tag -d <tagname>
  git push  origin :refs/tags/[tagName]
  git show [tag]
  git push [remote] [tag]
  git push [remote] --tags
  git checkout -b [branch] [tag]

七、查看信息

  git status
  git log
  - git log --stat
   git log -S [keyword]
   git log [tag] HEAD --pretty=format :%s
   git log [tag] HEAD --grep feature
   git log --follow [file]
   git whatchanged [file]
   git log -p [file]
   git log -5 --pretty --oneline
  git shortlog -sn
   git blame [file]
git diff
  git  diff --cached [file]
 git  diff HEAD
 git  diff [first- branch]...[ second- branch]
 git  diff --shortstat "@{0 day ago}"
 git  show [commit]
 git  show --name -only [commit]
git  show [commit]:[filename]
git  reflog

八、远程操作

 git fetch [remote]
git pull [remote] [branch]
 git remote -v
 git remote show [remote]
git remote add [shortname] [url]

-上传本地指定分支到远程仓库

git push [remote] [branch]
git push [remote] --force
git push [remote] --all
git push <remote>:<branch/tag-name>  
git push -- tags

九、撤销

git reset --hard HEAD  
git checkout HEAD <file>
git revert <commit>
git log --before="1 days"
 git checkout [file]
 git checkout [commit] [file]
 git checkout .
 git reset [file]
git reset --hard
git reset [commit]
git reset --hard [commit]
git reset --keep [commit]
 git revert [commit]
 git stash
 git stash pop

十、其他
生成一个可供发布的压缩包

git ar chive





完结,如有问题,请M我。

上一篇 下一篇

猜你喜欢

热点阅读