当前位置:   article > 正文

git命令大全_git指令 当前目录

git指令 当前目录

创建版本库

$ mkdir learngit
$ cd learngit
$ pwd
/Users/michael/learngit
  • 1
  • 2
  • 3
  • 4

pwd命令用于显示当前目录。在我的Mac上,这个仓库位于/Users/michael/learngit。

初始化仓库 git init

$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
  • 1
  • 2

添加文件到仓库 git add

$ git add readme.txt
  • 1

提交 git commit

$ git commit -m "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt
  • 1
  • 2
  • 3
  • 4

-m 后面输入的是本次提交的说明

查看当前仓库状态 git status

$ 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:   readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查看版本区别 git diff

$ git diff readme.txt 
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
 Git is free software.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查看版本历史 git log

$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Tue Aug 20 15:11:49 2013 +0800

    append GPL

commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Tue Aug 20 14:53:12 2013 +0800

    add distributed

commit cb926e7ea50ad11b8f9e909c05226233bf755030
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Mon Aug 19 17:51:55 2013 +0800

    wrote a readme file
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

简化显示历史版本信息git log --pretty=oneline

$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
  • 1
  • 2
  • 3
  • 4

回退版本git reset

$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed
  • 1
  • 2
参数含义
HEAD当前版本
HEAD^上一版本
HEAD^^上上一个版本
HEAD~100往上100个版本

回退到某一版本

$ git reset --hard 3628164
HEAD is now at 3628164 append GPL
  • 1
  • 2

查看git历史指令 git reflog

$ git reflog
ea34578 HEAD@{0}: reset: moving to HEAD^
3628164 HEAD@{1}: commit: append GPL
ea34578 HEAD@{2}: commit: add distributed
cb926e7 HEAD@{3}: commit (initial): wrote a readme file
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

撤销修改git checkout -- file

$ git checkout -- readme.txt
  • 1

撤销有两种情况:

一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。

删除文件git rm file

$ rm test.txt
  • 1

创建+切换分支git checkout -b name

$ git checkout -b dev
Switched to a new branch 'dev'
  • 1
  • 2

查看所有分支 git branch

$ git branch
* dev
  master
  • 1
  • 2
  • 3

切换分支 git checkout name

$ git checkout master
Switched to branch 'master'
  • 1
  • 2

合并分支 git merge name

$ git merge dev
Updating d17efd8..fec145a
Fast-forward
 readme.txt |    1 +
 1 file changed, 1 insertion(+)
  • 1
  • 2
  • 3
  • 4
  • 5

删除分支 git branch -d name

$ git branch -d dev
Deleted branch dev (was fec145a).
  • 1
  • 2

强行丢弃没有合并的分支git branch -D name

$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 756d4af).
  • 1
  • 2

忽略已跟踪文件的改动

git update-index --assume-unchanged name
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/120204
推荐阅读
相关标签
  

闽ICP备14008679号