美文网首页
git 常用命令初级

git 常用命令初级

作者: qqqywy | 来源:发表于2018-09-17 09:23 被阅读0次

    本地仓库常用命令

    git init :创建版本库
    git add hello.txt 版本加入git
    git status:状态显示
    git comiit -m "create hello.txt file 创建记录
    git reset --hard commit id 版本回退
    git reflog: 版本历史

    命令行测试

    C:\Users\lenovo>git config --global user.name "YE"

    C:\Users\lenovo>git config --global user.email "999999999@qq.com"

    C:\Users\lenovo>d:

    D:>mkdir learngit

    D:>cd learngit

    D:\learngit>git init
    Initialized empty Git repository in D:/learngit/.git/

    D:\learngit>git add hello.txt

    D:\learngit>git status
    On branch master

    No commits yet

    Changes to be committed:
    (use "git rm --cached <file>..." to unstage)

        new file:   hello.txt
    

    D:\learngit>git commit -m "create hello.txt File"
    [master (root-commit) ed64090] create hello.txt File
    1 file changed, 1 insertion(+)
    create mode 100644 hello.txt

    D:\learngit>git status
    On branch master
    nothing to commit, working tree clean

    D:\learngit>git add hello.txt

    D:\learngit>git commit -m "add a new line"
    [master d0a9868] add a new line
    1 file changed, 2 insertions(+), 1 deletion(-)

    D:\learngit>git status
    On branch master
    nothing to commit, working tree clean

    D:\learngit>git log
    commit d0a98689ad1fde99c89c7f087cc573dba22b02d3 (HEAD -> master)
    Author: YEndless 895315416@qq.com
    Date: Mon Sep 17 08:56:39 2018 +0800

    add a new line
    

    commit ed640904c571a48749b241a6b43053330de36740
    Author: YEndless 895315416@qq.com
    Date: Mon Sep 17 08:54:51 2018 +0800

    create hello.txt File
    

    D:\learngit>git reset --hard ed640
    HEAD is now at ed64090 create hello.txt File

    D:\learngit>git reset --hard d0a98
    HEAD is now at d0a9868 add a new line

    D:\learngit>git add src

    D:\learngit>git commit -m"add src file "
    [master dd29b5f] add src file
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 src/Student.java

    D:\learngit>git status
    On branch master
    nothing to commit, working tree clean

    D:\learngit>git log
    commit dd29b5fe1b4d3b27b2c519c2fd09bff899090ad6 (HEAD -> master)
    Author: YEndless 895315416@qq.com
    Date: Mon Sep 17 09:05:41 2018 +0800

    add src file
    

    commit d0a98689ad1fde99c89c7f087cc573dba22b02d3
    Author: YEndless 895315416@qq.com
    Date: Mon Sep 17 08:56:39 2018 +0800

    add a new line
    

    commit ed640904c571a48749b241a6b43053330de36740
    Author: YEndless 895315416@qq.com
    Date: Mon Sep 17 08:54:51 2018 +0800

    create hello.txt File
    

    D:\learngit>git reflog
    dd29b5f (HEAD -> master) HEAD@{0}: commit: add src file
    d0a9868 HEAD@{1}: reset: moving to d0a98
    ed64090 HEAD@{2}: reset: moving to ed640
    d0a9868 HEAD@{3}: reset: moving to d0a98
    d0a9868 HEAD@{4}: commit: add a new line
    ed64090 HEAD@{5}: commit (initial): create hello.txt File


    11.png

    相关文章

      网友评论

          本文标题:git 常用命令初级

          本文链接:https://www.haomeiwen.com/subject/xdahnftx.html