Skip to content

Instantly share code, notes, and snippets.

@iHaPBoy
Last active May 18, 2016 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iHaPBoy/cbdeac3a4f3d9932d6a4 to your computer and use it in GitHub Desktop.
Save iHaPBoy/cbdeac3a4f3d9932d6a4 to your computer and use it in GitHub Desktop.

#Git 基本操作

##配置个人信息

git config --global user.name XXX
git config --global user.email XXX@xxx.com

##从服务器克隆下来

git clone XXXX

##状态

git status 显示当前所处分支与修改(包括暂存与未暂存)
git checkout HEAD -- <file> 使某个文件恢复到上次提交时的状态
git checkout -- <file> 使某个文件恢复到上次暂存时的状态
git reset HEAD <file> 使某个修改由已暂存变为未暂存
将本地仓库重置成与远端一样:git fetch origin git reset --hard origin/master

##提交代码到版本库

git add .
git commit -m "XXX"

或者,你也可以这样:

git commit -am "XXX"

##提交到服务器

git push -u origin master
git push

##从服务器拉取

git pull

Git 常用别名

几乎每个人都会使用一些方法比如 Git 别名来提高效率,几乎所有人都会把使用git st来代替git status。然而这需要手动设置,每个人也都不完全一样。

Oh My Zsh 提供了一套系统别名(alias),来达到相同的功能。比如gst作为git status的别名。而且 Git 插件是 Oh My Zsh 默认启用的,相当于你使用了 Oh My Zsh,你就拥有了一套高效率的别名,而且还是全球通用的。是不是棒棒哒?下面是一些我常用的别名:

Alias Command
gapa git add --patch
gc! git commit -v --amend
gcl git clone --recursive
gclean git reset --hard && git clean -dfx
gcm git checkout master
gcmsg git commit -m
gco git checkout
gd git diff
gdca git diff --cached
glola git log --graph --pretty = format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all
gp git push
grbc git rebase --continue
gst git status
gup git pull --rebase
gwip git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"

完整列表请参考:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git

##生成SSH Key

ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
cat ~/.ssh/id_rsa.pub

扩展阅读 https://www.ivancai.me/2014/11/15/git-tutorial-for-beginner.html http://rogerdudler.github.io/git-guide/index.zh.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment