Git常用命令

在github下初建并提交

1
2
3
4
5
6
7
8
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某一个版本到当时分支

1
git pull origin dev_brisk_cgg

看远程分支

1
git branch -r

从本地cog提交远程master

1
git push origin cog:master

取消对文件的修改

1
$ git checkout -- benchmarks.rb

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

1
git reset HEAD^

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

1
2
$ git add xxx
$ git commit --amend

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

1
git show HEAD

占存切换分支

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ 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

取消已经暂存的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ 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
#

文件某个文件的日志

1
2
3
git log -p filename
gitk filename

继续补充中。。。。

原文地址:http://dlj.bz/xzGAvG

Comments