GitHub创建仓库提示代码
新建仓库
echo "# 项目名" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:pidada/项目名.git
git push -u origin master
若仓库存,在直接push
git remote add origin git@github.com:pidada/test.git
git push -u origin master
常用操作
创建仓库(初始化)
在当前指定目录下创建
git init
新建一个仓库目录
git init [project-name]
克隆一个远程项目
git clone [url]
添加文件到缓存区
添加所有变化的文件
git add .
添加名称指定文件
git add text.txt
配置
设置提交代码时的用户信息
git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
提交
提交暂存区到仓库区
git commit -m "msg"
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git commit --amend [file1] [file2] ...
远程同步
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
标签Tags
添加标签 在当前commit
git tag -a v1.0 -m 'xxx'
添加标签 在指定commit
git tag v1.0 [commit]
查看
git tag
删除
git tag -d V1.0
删除远程tag
git push origin :refs/tags/[tagName]
推送
git push origin --tags
拉取
git fetch origin tag V1.0
新建一个分支,指向某个tag
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 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 archives