git命令使用

                     git命令详情

1.初始化git init

[root@foundation30 demo]# git init
Initialized empty Git repository in /root/demo/.git/
[root@foundation30 demo]# l.
.  ..  .git
[root@foundation30 demo]# cd .git/
[root@foundation30 .git]# ls
branches  description  hooks  objects
config    HEAD         info   refs

2.状态查看

git status;git ststus -s(最简)
 M README
MM Rakefile
A  lib/git.rb
M  lib/simplegit.rb
?? LICENSE.txt

新添加的未跟踪文件前面有 ?? 标记,新添加到暂存区中的文件前面有 A 标记,修改过的文件前面有 M 标记。 你可能注意到了 M 有两个可以出现的位置,出现在右边的 M 表示该文件被修改了但是还没放入暂存区,出现在靠左边的 M 表示该文件被修改了并放入了暂存区。 例如,上面的状态报告显示: README 文件在工作区被修改了但是还没有将修改后的文件放入暂存区,lib/simplegit.rb 文件被修改了并将修改后的文件放入了暂存区。 而 Rakefile 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录
3.添加;提交

git add readme.md
[root@foundation30 demo]# git add readme.md 
[root@foundation30 demo]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   readme.md
#
[root@foundation30 demo]# git status -s
A  readme.md
 git commit -m 'add readme.md'
 [root@foundation30 demo]# git commit -m 'add readme.md'
[master (root-commit) 2fac4ae] add readme.md
 Committer: root <root@foundation30.ilt.example.com>

4.忽略隐藏文件:

文件 .gitignore 的格式规范如下:

所有空行或者以 # 开头的行都会被 Git 忽略。

可以使用标准的 glob 模式匹配。

匹配模式可以以(/)开头防止递归。

匹配模式可以以(/)结尾指定目录。

要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。

5.全局变量

[root@foundation30 demo]# git config --global user.name wei
[root@foundation30 demo]# git config --global user.email "dreamer@westos.org"
[root@foundation30 demo]# cd
[root@foundation30 ~]# l.
.              .gitconfig        .viminfo
[root@foundation30 ~]# cat .gitconfig
[user]
        name = wei
        email = dreamer@westos.org

5.日至

[root@foundation30 demo]# git log
commit 0eb4a4aab961c461c98bee8f6b2c7aeda099c0fc
Author: wei <dreamer@westos.org>
Date:   Fri Aug 24 01:32:40 2018 +0800

    add test.txt

commit 2fac4ae85a3b4b6caa0ff63fb9a52ed46c14adba
Author: root <root@foundation30.ilt.example.com>
Date:   Fri Aug 24 01:27:20 2018 +0800

    add readme.md
[root@foundation30 demo]# git log --pretty=oneline
0eb4a4aab961c461c98bee8f6b2c7aeda099c0fc add test.t
2fac4ae85a3b4b6caa0ff63fb9a52ed46c14adba add readme

6.回退
通过16进制将每个文件状态标记区分利用指针进行定位
工作目录下的每一个文件都不外乎这两种状态:已跟踪或未跟踪。 已跟踪的文件是指那些被纳入了版本控制的文件,在上一次快照中有它们的记录,在工作一段时间后,它们的状态可能处于未修改,已修改或已放入暂存区。 工作目录中除已跟踪文件以外的所有其它文件都属于未跟踪文件,它们既不存在于上次快照的记录中,也没有放入暂存区。 初次克隆某个仓库的时候,工作目录中的所有文件都属于已跟踪文件,并处于未修改状态。
编辑过某些文件之后,由于自上次提交后你对它们做了修改,Git 将它们标记为已修改文件。 我们逐步将这些修改过的文件放入暂存区,然后提交所有暂存了的修改,如此反复。所以使用 Git 时文件的生命周期如下:

[root@foundation30 demo]# git reset --hard HEAD^
HEAD is now at 2fac4ae add readme.md
[root@foundation30 demo]# ls
readme.md
[root@foundation30 demo]# cat readme.md 
westos
[root@foundation30 demo]# git log --pretty=oneline
2fac4ae85a3b4b6caa0ff63fb9a52ed46c14adba add readme
[root@foundation30 demo]# rm -f readme.md 
[root@foundation30 demo]# git reflog
2fac4ae HEAD@{0}: reset: moving to HEAD^
0eb4a4a HEAD@{1}: commit: add test.txt
2fac4ae HEAD@{2}: commit (initial): add readme.md
[root@foundation30 demo]# git reset --hard 0eb4a4a
HEAD is now at 0eb4a4a add test.txt
[root@foundation30 demo]# ls
readme.md  test.txt
[root@foundation30 demo]# git status -s
[root@foundation30 demo]# vim test.txt 
[root@foundation30 demo]# git status -s
 M test.txt
[root@foundation30 demo]# git checkout -- test.txt 
[root@foundation30 demo]# cat test.txt 
westos
[root@foundation30 demo]# vim test.txt 
[root@foundation30 demo]# 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:   test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@foundation30 demo]# git checkout -- test.txt 
[root@foundation30 demo]# git status # On branch master
nothing to commit, working directory clean
[root@foundation30 demo]# git reset HEAD
[root@foundation30 demo]# git reset HEAD test.txt 
[root@foundation30 demo]# ls
readme.md  test.txt
[root@foundation30 demo]# cat test.txt 
westos

5. 本地推送

[root@foundation30 demo]# ssh-keygen 
[root@foundation30 demo]# cd
[root@foundation30 ~]# cd .ssh/
[root@foundation30 .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCT0DlAuxP9QWmzOpkPrBomsWsBmZtpy/QZgpCpx6HArY2E9jWa/BZJ3dlhrlM4A22p/Ss0y+o5b5QK/aQhYYVU+n3zsm3pdZyhakuTLYep7tdaMwd1AHT3yarUgSt5AXaL4gOOtyxTkD/frUDmTWdMXFk02cdNa7YTfllOK1KG4qBYNI9/SX7g4NtgYwQ2DE/eanUddwretXVnVzrOeGW3YZjxIyORf/I02Na+sbRqhAIi+YLG7kDSUpfPtdPUdjLsrs6j9b0xxx9qWLhrvbbiswVisBZFxSWFlFQw7EPFENye3KAk0UW+BSj3DBR9LWy/BT9vka3U/X1V3/1QKtB3 root@foundation30.ilt.example.com

ssh放公钥:

[root@foundation30 demo]# git remote add origin https://github.com/dreamerxixixi/root.git #通过http从本地推送需要输入密码和用户
[root@foundation30 demo]# git push -u origin master
Username for 'https://github.com': dreamerxixixi
Password for 'https://dreamerxixixi@github.com': 
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 661 bytes | 0 bytes/s, done.
Total 8 (delta 0), reused 0 (delta 0)
To https://github.com/dreamerxixixi/root.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
[root@foundation30 demo]# cat readme.md 
westos
westos
Westos


8 .远程推送—->本地拉取:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值