git常用命令

在github下初建并提交

git init 
git remote add origin git@github.com:xxxx/xxxx.git
git pull origin master
git branch cgg #本地分支
vi README
git add README
git commit -m "brinch cgg update master"
git pull origin master 

pull某一个版本到当时分支

git pull origin dev_brisk_cgg 

看远程分支

git branch -r

从本地cog提交远程master

git push origin cog:master 

取消对文件的修改

$ git checkout -- benchmarks.rb

本地取消最后一个commit(代码不会还原)

git reset HEAD^

如果commit以后还想添加到本地中

$ git add xxx
$ git commit --amend

任何标识或其他修改。 或使用gitk浏览视觉的变化。

git show HEAD 

占存切换分支

$ git add config/deploy.rb
$ git checkout cgg_stable

error: Your local changes to the following files would be overwritten by checkout:
    config/deploy.rb
Please, commit your changes or stash them before you can switch branches.
error: Your local changes to the following files would be overwritten by checkout:
    config/environments/development.rb
Please, commit your changes or stash them before you can switch branches.
Aborting

$ git stash
Saved working directory and index state WIP on master: 3465109 thin edit
HEAD is now at 3465109 thin edit

$ git checkout cgg_stable
Switched to branch 'cgg_stable'

$ git checkout master
Switched to branch 'master'

$ git stash list
stash@{0}: WIP on master: 3465109 thin edit

$ git stash apply stash@{0}
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   config/deploy.rb
#   modified:   config/environments/development.rb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   public/profile/
#   vendor/cache/
$ git stash clear 

取消已经暂存的文件

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   README.txt
#       modified:   benchmarks.rb
#

$ git reset HEAD benchmarks.rb
benchmarks.rb: locally modified
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   README.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   benchmarks.rb
#

文件某个文件的日志

git log -p filename 
或
gitk filename

继续补充中。。。。

Comments