Lee_3do的博客

Git简明手册

2015-11-12  本文已影响46人  lee_3do
$ git init test
Initialized empty Git repository in /home/tstcit/Git/test/.git/
$ git add read.txt
$ git commit -m "hello Git"
[master (root-commit) 57cb487] hello Git
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 read

注意使用-m命令来写更新描述

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   read
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff read
diff --git a/read b/read.txt
index e69de29..802d8e8 100644
--- a/read.txt
+++ b/read.txt
@@ -0,0 +1 @@
+sfds
$ git log
commit 57cb48772f15d42d8aba170b21cfd85b50c07818
Author: lee_3do <lee3do@gmail.com>
Date:   Thu Nov 12 16:37:44 2015 +0800

    hello Git
$ git reset --hard 57cb48772f15d42d8aba170b21cfd85b50c07818
HEAD is now at 57cb487 hello Git

57cb48772f15d42d8aba170b21cfd85b50c07818是某个commit id,可以指定任意一个存在的commit id,回退或者前进道指定版本.
HEAD指向的版本就是当前版本

$ git reflog
57cb487 HEAD@{0}: reset: moving to 57cb48772f15d42d8aba170b21cfd85b50c07818
f78caa3 HEAD@{1}: commit: s
57cb487 HEAD@{2}: commit (initial): hello Git
$ git checkout -- read.txt

这里有两种情况:
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。

$ git reset HEAD readme.txtUnstaged changes after reset:M readme.txt

然后在执行 git checkout -- read.txt命令丢弃工作期的修改.

$ git rm read
$ git branch dev
$ git checkout dev
$ git branch
*dev
 master

*号后表示当前分支,master是默认分支

$ git merge dev
Updating d17efd8..fec145a
Fast-forward
 readme.txt | 1 +
 1 file changed, 1 insertion(+)
$ git branch -d dev
Deleted branch dev (was fec145a).
$ git stash
Saved working directory and index state WIP on dev: 6224937 add mergeHEAD is now at 6224937 add merge
$ git stash list
stash@{0}: WIP on dev: 6224937 add merge
$ git stash apply stash@{0}
$ git stash pop

恢复的同时把stash内容也删了.

git remote -v
git push origin branch-name
git checkout -b branch-name origin/branch-name
git branch --set-upstream branch-name origin/branch-name
git pull
$ git tag v1.0
git show <tagname>
$ git tag -a v0.1 -m "version 0.1 released" 3628164

-a指定标签名,-m指定说明文字,3628164是commit id.

$ git config --global alias.st status

以后st就表示status.
也可以修改配置文件.git/config,或者.gitconfig.

上一篇 下一篇

猜你喜欢

热点阅读