学习笔记:03_如何使用Git命令把文件提交到版本库

学习笔记:03_如何使用Git命令把文件提交到版本库

Git常见的命令

  • 获取版本库
    • git init 初始化本地空的版本库
    • git clone
  • 版本管理
    • git add 当前以修改的文件拉入git的暂存区中
    • git commit
    • gi rm
  • 查看信息
    • git help
    • git log
    • git diff 比较差别
  • 远程协助
    • git pull
    • git push
git 文件三种状态:
     以修改  
     以暂存  
     已提交
     
master 主分支  在mater分支中发布项目 (master分支是默认的分支)    

.git目录

mkdir myGit #创建myGit文件
cd myGit #进入myGit
git init # 初始化git
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cd .git

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ ll
total 7
-rw-r--r-- 1 Administrator 197121 130 八月   20 21:09 config
-rw-r--r-- 1 Administrator 197121  73 八月   20 21:09 description
-rw-r--r-- 1 Administrator 197121  23 八月   20 21:09 HEAD
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 hooks/
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 info/
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 objects/
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 refs/

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)

把修改的文件添加到版本库


Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ touch test.txt

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ ll
total 0
-rw-r--r-- 1 Administrator 197121 0 八月   20 21:35 test.txt

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ vim test.txt

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you_01

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.txt

nothing added to commit but untracked files present (use "git add" to track)

Administrator@kevin MINGW32 ~/Desktop/myGit (master)

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master

No commits yet

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


Administrator@kevin MINGW32 ~/Desktop/myGit (master)


git文件从暂存区回退到以修改状态:git rm 命令

$ git rm test.txt
error: the following file has changes staged in the index:
    test.txt
(use --cached to keep the file, or -f to force removal)

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master

No commits yet

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


Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$

git commit必须写注释否则:
格式: git commit -m ‘注释’

$ git commit

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Administrator@kevin.(none)')

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git commit -m '测试'

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Administrator@kevin.(none)')

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$

对于user.name 与user.email来说有三个地方可以设置

  • /etc/.gitconfig 针对某个整个操作系统
  • ~/.gitconfig 针对特定的用户。 git config –global
  • 针对特定的项目 .git/config文件中 git config –local
$ git config
usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file


Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config --global user.name 'zx'

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config --global user.email '892295771@qq.com'

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$

$ git commit -m '测试'
[master (root-commit) ba82baf] 测试
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
nothing to commit, working tree clean

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config
usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --get-urlmatch        get value specific for the URL: section[.var] URL
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-regex]
    --unset-all           remove all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            open an editor
    --get-color           find the color configured: slot [default]
    --get-colorbool       find the color setting: slot [stdout-is-tty]

Type
    -t, --type <>         value is given this type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)
    --expiry-date         value is an expiry date

Other
    -z, --null            terminate values with NUL byte
    --name-only           show variable names only
    --includes            respect include directives on lookup
    --show-origin         show origin of config (file, standard input, blob, command line)
    --default <value>     with --get, use default value when missing entry


Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$

git config –local操作

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ ll
total 9
-rw-r--r-- 1 Administrator 197121   7 八月   20 22:06 COMMIT_EDITMSG
-rw-r--r-- 1 Administrator 197121 148 八月   20 22:10 config
-rw-r--r-- 1 Administrator 197121  73 八月   20 21:09 description
-rw-r--r-- 1 Administrator 197121  23 八月   20 21:09 HEAD
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 hooks/
-rw-r--r-- 1 Administrator 197121 137 八月   20 21:45 index
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 info/
drwxr-xr-x 1 Administrator 197121   0 八月   20 22:06 logs/
drwxr-xr-x 1 Administrator 197121   0 八月   20 22:06 objects/
drwxr-xr-x 1 Administrator 197121   0 八月   20 21:09 refs/

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        name = zz

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zx'

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.email 'xxx@qq.com'

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        name = zx
        email = xxx@qq.com

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config -l
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=d:/Program Files/Git/mingw32/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge --skip -- %f
filter.lfs.process=git-lfs filter-process --skip
filter.lfs.required=true
pack.packsizelimit=2g
add.interactive.usebuiltin=true
user.name=zx
user.email=892295771@qq.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.name
zx

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.email
xxx@qq.com

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zdd'

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local --unset user.name

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        email = xxx@qq.com

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zx'

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.name
zx

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.email
xxx@qq.com

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[user]
        email = xxx@qq.com
        name = zx

Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat ~/.gitconfig
[user]
        name = zx
        email = 892295771@qq.com

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
$ echo 'i love you to'>test.txt

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you to

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git commit -m '再次修改为 iloveyou to'
[master 9b79eb7] 再次修改为 iloveyou to
 1 file changed, 1 insertion(+), 1 deletion(-)

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you to

Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git log
commit 9b79eb743639cfd7b6e62966d6012403ce3b3fd0 (HEAD -> master)
Author: zx <xxx@qq.com>
Date:   Tue Aug 20 22:24:52 2019 +0800

    再次修改为 iloveyou to

commit ba82bafa862d0cccdd105e725f2e17f711a321eb
Author: zx <892295771@qq.com>
Date:   Tue Aug 20 22:06:58 2019 +0800

    测试

Administrator@kevin MINGW32 ~/Desktop/myGit (master)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100780.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux查看java进程内存使用情况_java查看线程状态

    linux查看java进程内存使用情况_java查看线程状态1.查看java进程内存占用top-b-n1|grepjava|awk'{print”PID:”$1″,mem:”$6″,CPUpercent:”$9″%”,”mempercent:”$10″%”}’2.查看pid所在目录lsof-pPID3.查看剩余内存free-m

    2022年8月24日
    8
  • 华为pimsm组播配置_华为m6卡槽

    华为pimsm组播配置_华为m6卡槽当你想要放弃了,一定要想想那些睡得比你晚、起的比你早、跑得比你卖力、天赋比你还高的牛人,他们早已在晨光中,跑向那个你永远只能眺望的远方。—马云文章目录一、组播地址划分二、拓扑三、基本配置四、PIM-SM的RPT共享树构建五、PIM六、PIM-SM的SPT七、PIM-SM基本概述PIM-SM(ProtocolIndependentMulticast-SparseMode)称为协议无关组播-稀疏模式。属于稀疏模式的组播

    2022年9月23日
    0
  • java正则表达式匹配数字范围_在java中怎么利用正则表达式匹配数字

    java正则表达式匹配数字范围_在java中怎么利用正则表达式匹配数字在java中怎么利用正则表达式匹配数字发布时间:2020-12-0317:47:12来源:亿速云阅读:58作者:Leah在java中怎么利用正则表达式匹配数字?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。用于匹配的正则表达式为:([1-9]\d*\.?\d*)|(0\.\d*[1-9])([1-9]:匹配1~9的数字;\d…

    2022年6月21日
    32
  • oracle的minus返回第一个表中有、第二个表中没有的数据

    oracle的minus返回第一个表中有、第二个表中没有的数据推荐:http://www.cnblogs.com/roucheng/p/3504463.html

    2021年12月23日
    41
  • 深度搜索算法查找最短路径的方法_深度优先搜索算法

    深度搜索算法查找最短路径的方法_深度优先搜索算法如图,百度地图上有5个地点,各个地点间是单向的路径,试求出从1到5的最短路径。从图中可以得到一个5*5的二维矩阵,利用深度搜索算法,求出最短路径。从最后的运行结果,可以直观的看出搜索的过程代码实现如下:#include"pch.h"#include&lt;stdio.h&gt;#include&lt;stdlib.h&gt;#include&lt;vector&g…

    2025年6月6日
    1
  • 基于pytorch卷积人脸表情识别–毕业设计「建议收藏」

    基于卷积神经网络的人脸表情识别前言毕业设计内容介绍卷积神经网络的设计卷积网络的模型卷积池化过程详细说明第一层卷积池化过程第二层卷积池化过程第三层卷积池化过程全连接层过程模型的训练过程卷积与池化原理模型如何训练模型的评估指标训练结果分析通过训练曲线分析通过混淆矩阵分析效果通过摄像头识别表情设计流程效果演示部分代码展示总结前言这篇文章记录一下我本科毕业设计的内容。我的课题是人脸表情识别,本来最开始按照历届学长的传统是采用MATLAB用传统的机器学习方法来实现分类的。但是鉴于我以前接触过一点点深度学习的内容,

    2022年4月11日
    159

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号