编程常用工具命令3 Git

在这里插入图片描述
git常用命令:

master 默认开发分支origin默认远程版本库Head默认开发分支Head^ Head的父提交

git clone url 克隆远程版本库git init 初始化本地库本库

修改和提交git status 查看状态git diff 查看变更内容git add . 跟踪所有改动过的文件git add file 跟踪指定的文件git mv old new 文件改名git rm file 删除文件git rm —cached file 停止跟踪文件但不删除git commit -m “commit messages” 提交所有更新过的文件git commit —amend 修改最后一次改动

查看提交历史git log 查看提交历史git log -p file 查看指定文件的提交历史git blame file 以列表方式查看指定文件的提交历史git diff —cached filename 查看本地已经add但是没有commit的文件修改情况git diff filename 查看变更但是没有add的修改情况

撤销git reset —hard HEAD 撤销工作目录中所有未提交文件的修改内容git checkout HEAD file 撤销指定的未提交文件的修改内容git checkout — readme.txt 丢弃工作区指定文件的修改git revert commit 撤销指定的提交git log —before = “1 days” 退回到之前一天的版本

分支与标签git branch 显示所有本地分支git checkout branch/tag 切换到指定分支和标签git branch new-branch 创建新分支git branch -d branch 删除本地分支git tag 列出所有本地标签git tag tagname 基于最新提交的创建标签git tag -d tagname 删除标签git checkout origin/remoteName -b localName 将远程分支拉取到本地分支(没有则自动创建)

合并与衍合git merge branch 合并指定分支到当前分支git rebase branch 衍合指定分支到当前分支git cherry-pick commitId 将其他分支的指定commit合并到当前分支

远程操作git remote -v 查看远程版块库信息git remote show remote 查看指定远程版本库信息git remote add remote url 添加远程版本库git fetch remote 从远程库获取代码git pull remote branch 下载代码即快速合并git push remote branch 上传代码及快速合并git push remote :branch/tag-name 删除远程分支或标签git push —tags 上传所有标签

远程回滚git push -f origin develop 强制将远程回滚到本地版本,需要先将本地库回滚到指定版本

usage: git [–version] [–help] [-C ] [-c =][–exec-path[=]] [–html-path] [–man-path] [–info-path][-p | --paginate | -P | --no-pager] [–no-replace-objects] [–bare][–git-dir=] [–work-tree=] [–namespace=][]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)clone Clone a repository into a new directoryinit Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)add Add file contents to the indexmv Move or rename a file, a directory, or a symlinkrestore Restore working tree filesrm Remove files from the working tree and from the indexsparse-checkout Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)bisect Use binary search to find the commit that introduced a bugdiff Show changes between commits, commit and working tree, etcgrep Print lines matching a patternlog Show commit logsshow Show various types of objectsstatus Show the working tree status

grow, mark and tweak your common historybranch List, create, or delete branchescommit Record changes to the repositorymerge Join two or more development histories togetherrebase Reapply commits on top of another base tipreset Reset current HEAD to the specified stateswitch Switch branchestag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)fetch Download objects and refs from another repositorypull Fetch from and integrate with another repository or a local branchpush Update remote refs along with associated objects

‘git help -a’ and ‘git help -g’ list available subcommands and someconcept guides. See ‘git help ’ or ‘git help ’to read about a specific subcommand or concept.See ‘git help git’ for an overview of the system.

git安装:

git官网 检验是否安装成功用 git —version 查看版本 出现gitbash命令行工具

Ubuntu sudo apt-get install gitCentOS sudo yum install git

git 基本命令git add filename 将文件添加到暂存区git add . 将工作目录下的所有修改的文件添加到暂存区

git commit -m ‘description’ 将暂存区内的文件提交到版本库git commit -am ‘description’ 跳过git add 添加到暂存区命令 直接将工作区所有的已追踪的文件提交

git log 查看目录

git status 查看项目文件状态

git config – global user.name Orpheusgit config – global user.email [email protected] config – listgit config 地址~/ .gitconfig

在相应目录下进行初始化git init 初始化git仓库 出现.git文件

git status 查看是否被追踪

git中文件的4种状态:untracked 未被追踪modified 表示工作区修改了某个文件但是还没有添加到暂存区staged 表示把工作区修改的文件添加到了暂存区但是没有提交到版本库committed 表示数据被安全的存储在本地库中

git的3层结构working directory 工作区staging index 暂存区git directory(Repository)版本库

add把文件从工作区添加到暂存区 committed从暂存区提交到版本库git add git.htmlgit commit -m ‘first commit’git commit -am ‘remodified git.html’ 一次完成

git撤销操作git checkout - - filename 拉取暂存区的文件并将其替换工作区的文件,注意与git checkout branchname区别git reset HEAD - - filename 拉取最近一次提交的版块库中的这个文件到暂存区,该操作不影响工作区git commit - - amend 撤销上一次提交 并将暂存区的文件重新提交

git删除文件git rm - - filename 删除工作区及暂存区中的该文件相当于删除文件后执行 git addgit rm —cached filename 在不小心将不需要追踪的文件添加到暂存区,想删除暂存的文件但是不想删除工作区的文件很有用git rm -f filename 当工作区或者暂存区文件修改了 防止把修改误删除了glob模式

git mv filename相当于1.mv oldname newname 2.git rm oldname 3.git add newname

git分支 git分支的创建,修改,切换,删除git branch 查看分支git branch branchname 创建分支git branch -m oldname newname 修改分支名称git checkout [-b] branchname 切换分支git branch -D branchname 删除分支

分支的合并分支的指针 HEAD指针指向当前工作的分支 在切除分支时指向新的分支git diffgit diff 比较工作区与暂存区文件的差异git diff - - staged 比较暂存区与版本库的文件差异git diff 版本号 版本号 比较分支内的两个版本的差异git diff 分支 分支 比较两个分支的最新提交版本的差异

甲 远程仓库 乙甲先push到远程仓库乙进行下载用clone然后把修改的push到远程仓库甲想要看则需要pull下来

git ssh免密登陆。ssh-keygenssh-copy id user@host

git帮助文档的使用git helpgit help command官方文档地址 git

Git 是一个开源的分布式版本控制系统,用于敏捷高效的处理任何大小项目。不必服务器端软件支持

Git 不仅仅是个版本控制系统,也是个内容管理系统CMS,工作管理系统等Git是分布式的,把内容按元数据方式存储,分支就是版本库中的另一个目录,Git没有一个全局的版本号,Git的内容完整性要更优

一般工作流程:

clone Git资源作为工作目录在克隆的资源上添加或修改文件若其他人修改了,你可以更新资源在提交前进行查看修改提交修改在修改完后,若发现错误,可以撤回提交并再次修改并提交
在这里插入图片描述

Git工作区:就是在电脑上看到的目录暂存区:stage或index,一般是存放.git目录下的index文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)版本库:工作区有一个隐藏目录.git 这个不算工作区,而是Git的版本库
在这里插入图片描述

左侧为工作区,右侧为版本库 在版本库中标记为index的区域为暂存区(stage/index),标记为master的是master分支所代表的目录树

此时的HEAD实际指向master分支的一个游标。所以图示的命令中出现HEAD的地方可以用master来替换

图中objects标识的区域为Git的对象库,实际位于 .git/objects目录下,里面包含了创建的各种对象及内容

当对工作区修改(或新增)的文件git add命令时,暂存区的目录树被更新,同时工作区修改(或新增)的文件内容被写入到对象库中的一个新的对象中,而该对象的ID被记录在暂存区的文件索引中。

当执行提交操作 git commit 时,暂存区的目录树写到版本库(对象库)中,master分支会做相应的更新。即master指向的目录树就是提交时暂存区的目录树。

当执行git reset HEAD 命令时,暂存区的目录树会被重写,被master分支指向的目录树所替换,但是工作区不受影响

当执行git rm - - cached ,会直接从暂存区删除文件,工作区不做任何改变

当执行git checkout . 或者 git checkout - - ,会用暂存区全部或指定的文件替换工作区的文件。这个操作很危险,会清除工作区中未添加到暂存区中的改动

当执行git checkout HEAD . 或者 git checkout HEAD ,会用HEAD指向的master分支中的全部或者部分文件替换暂存区和以及工作区中的文件。这个命令也是极其危险的,因为不但会清除工作区中未提交的改动,也会清除暂存区中未提交的改动

Git创建仓库

可以使用一个已经存在的目录作为Git仓库git init 初始化一个Git仓库在执行完git init命令后,Git仓库会生成一个.git目录,该目录包含了资源的所有元数据,其他的项目目录保持不变

使用当前目录作为Git仓库,我们只需使它初始化 git init也可以使用指定目录作为指定仓库git init newrepo 初始化后,会在newrepo目录下出现一个.git的目录,所有Git需要的数据和资源都存放在这个目录中

如果当前目录下有几个文件想要纳入版本控制,需要先用git add命令告诉Git开始对这些文件进行追踪,然后提交git add *.pygit add READMEgit commit -m ‘初始化项目版本’

在Linux系统下,commit信息使用单引号’ Windows系统使用双引号“

在git bash 中git commit -m ‘提交说明’ 这样是可以的,在Windows中要用双引号

git clone从现有仓库中拷贝项目 类似于svn checkout克隆仓库命名格式为 git clone若需要克隆到指定目录 git clone

例如要克隆Ruby语言的Git代码仓库Grit,可以用一下命令:git clone git://github.com/schacon/grit.git执行后会在当前目录下创建一个名为grit的目录,其中包含一个.git目录,用于保存下载下来的所有版本记录

若要自定义新建的项目目录名称,可以在上面的命令末尾指定git clone git://github.com/schacon/grit.git mygrit

git的设置使用git config 命令显示当前的git配置信息:git config - - listcredential.helper = osxkeychaincore.repositoryformatversion = 0core.filemode = truecore.bare = falsecore.logallrefupdates = truecore.ignorecase = truecore.precomposeunicode = true

编辑git配置文件git config -e #针对当前仓库或者git config -e - - global #针对系统上所有仓库

设置提交代码时的用户信息git config - - global user.name “Orpheus”git config - - global user.email [email protected]

如果去掉 - - global参数只对当前仓库有效

Git的工作就是创建和保存你项目的快照及以后的快照进行对比git clone 拷贝一份远程仓库,也就是下载一个项目git pushgit add 添加文件到仓库git commitgit checkoutgit pull
在这里插入图片描述

一个简单操作步骤:

git initgit add .git commit

git init 初始化仓库git add . 添加文件到暂存区git commit 将暂存区内容添加到仓库中

git add 添加文件到仓库git status 查看仓库当前的状态,显示有变更的文件git diff 比较文件的不同,即暂存区和工作区的差异git commit 提交暂存区到本地仓库git reset 回退版本git rm 删除工作区文件git mv 移动或重命名工作区文件

git log 查看历史提交记录git blame 以列表形式查看指定文件的历史修改记录

git remote 远程仓库操作git fetch 从远程获取代码库git pull 下载远程代码并合并git push 上传远程代码并合并

几乎每一种版本控制系统都以某种形式支持分支。使用分支意味着可以从开发主线上分离开来,然后在不影响主线的同时继续工作。

Git的分支模型称为必杀技特性 正因为它,将Git从版本控制系统家族里区分出来git branch (branchname)

切换分支命令git checkout (branchname)

当你切换分支的时候,Git会用该分支的最后提交的快照替换你的工作目录的内容,所以多个分支不需要多个目录。合并分支命令git merge

可以多次合并到统一分支,也可以选择在合并之后直接删除被并入的分支

先创建一个测试目录: m k d i r g i t d e m o mkdir gitdemo mkdirgitdemocd gitdemo/ g i t i n i t I n i t i a l i z e d e m p t y G i t r e p o s i t o r y … git initInitialized empty Git repository… gitinitInitializedemptyGitrepositorytouch README g i t a d d R E A D M E git add README gitaddREADMEgit commit -m ‘first commit’[master (root-commit) 3b58100] first commit1 file changed,0 insertions(+) , 0 deletions(-)create mode 100644 README

Git分支管理列出分支git branch没有参数时,git branch会列出在你本地的分支

$git branch*master

此例的意思是,我们有一个叫master的分支,并且该分支是当前分支当你执行git init 的时候,默认情况下Git就会为你创建master分支如果我们要手动创建一个分支,执行git branch (branchname) 即可

g i t b r a n c h t e s t i n g git branch testing gitbranchtestinggit branch*mastertesting

现在可以看到,有一个新分支testing

当以此方式在上次提交更新之后创建了新分支,如果后来又有更新提交,然后又切换到了testing分支,Git将还原你的工作目录到你创建的分支时的样子

演示如何切换分支,用git checkout(branch)切换到我们要修改的分支 l s R E A D M E lsREADME lsREADMEecho ‘runoob.com’ > test.txt g i t a d d . git add . gitadd.git commit -m ‘add test.txt’[master 3e92c19] add test.txt1 file changed,1 insertion(+)create mode 100644 test.txt l s R E A D M E t e s t . t x t lsREADME test.txt lsREADMEtest.txtgit checkout testingSwitched to branch ‘testing’ l s R E A D M E lsREADME lsREADMEgit checkout master$lsREADME test.txt

当我们切换到testing分支时,我们添加的新文件test.txt被移除了。切换回master分支的时候,它们又重新出新了

也可以用git checkout -b(branchname) 来创建新分支并立即切换到该分支下,从而在该分支中操作 g i t c h e c k o u t − b n e w t e s t S w i t c h e d t o a n e w b r a n c h ‘ n e w t e s t ’ git checkout -b newtestSwitched to a new branch ‘newtest’ gitcheckoutbnewtestSwitchedtoanewbranchnewtestgit rm test.txtrm ’test.txt’ l s R E A D M E lsREADME lsREADMEtouch runoob.php g i t a d d . git add . gitadd.git commit -am ‘removed test.txt、add runoob.php’[newtest c1501a2] removed test.txt、add runoob.php’2 files changed, 1 deletion(-)create mode 100644 runoob.phpdelete mode 100644 test.txt l s R E A D M E r u n o o b . p h p lsREADME runoob.php lsREADMErunoob.phpgit checkout masterSwitched to branch ‘master’$lsREADME test.txt

我们创建了一个分支,在该分支上移除了一些文件test.txt,并添加了runoob.php文件,然后切换回我们的主分支,删除的test.txt文件又回来了,且新增加的runoob.php不存在主分支中使用分支将工作区分开来,从而让我们能够在不同开发环境中做事,并来回切换

删除分支:git branch -d (branchname)例如删除testing分支 g i t b r a n c h ∗ m a s t e r t e s t i n g git branch*mastertesting gitbranchmastertestinggit branch -d testingDeleted branch testing (was 85fc7e7)$git branch*master

分支合并一旦某分支有了独立内容,你终究希望将它合并回你的主分支,你可以使用一下命令将任何分支合并到当前分支中去:git merge

$git branch*masternewtest

l s R E A D M E t e s t . t x t lsREADME test.txt lsREADMEtest.txtgit merge newtestUpdating 3e92c19 …c1501a2Fast-forwardrunoob.php | 0test.txt | 1 -2 files changed , 1 deletion(-)create mode 100644 runoob.phpdelete mode 100644 test.txt

$lsREADME runoob.php

合并冲突合并不仅仅是简单的文件添加,移除的操作,Git也会合并并修改 g i t b r a n c h ∗ m a s t e r git branch*master gitbranchmastercat runoob.php

首先我们创建一个叫作change_site的分支,切换过去,我们将runoob.php改为

<?php echo ‘hello’; ?>

创建change_site分支: g i t c h e c k o u t − b c h a n g e s i t e S w i t c h e d t o a n e w b r a n c h ‘ c h a n g e s i t e ’ git checkout -b change_siteSwitched to a new branch ‘change_site’ gitcheckoutbchangesiteSwitchedtoanewbranchchangesitevim runoob.php$head -3 runoob.php

<?php echo ‘runoob’; ?>

$git commit -am ‘changed the runoob.php’[change_site 7774248] changed the runoob.php1 file changed,3 insertions(+)

将修改的内容提交到change_site分支中,现在假如切换回master分支我们可以看内容恢复到我们修改前的(空文件,没有代码),我们再次修改runoob.php文件$ git checkout masterSwitched to branch ‘master’$ cat runoob.php$ vim runoob.php # 修改内容如下$ cat runoob.php

<?php echo 1; ?>

$ git diffdiff --git a/runoob.php b/runoob.phpindex e69de29…ac60739 100644— a/runoob.php+++ b/runoob.php@@ -0,0 +1,3 @@+<?php +echo 1; +?>$ git commit -am ‘修改代码’[master c68142b] 修改代码1 file changed, 3 insertions(+)这些改变已经记录到我的 “master” 分支了。接下来我们将 “change_site” 分支合并过来。

$ git merge change_siteAuto-merging runoob.phpCONFLICT (content): Merge conflict in runoob.phpAutomatic merge failed; fix conflicts and then commit the result.

$ cat runoob.php # 代开文件,看到冲突内容

<?php <<<<<<< HEAD echo 1; ======= echo 'runoob'; >>>>>>> change_site ?>

将前一个分支合并到 master 分支,一个合并冲突就出现了,接下来我们需要手动去修改它。

$ vim runoob.php$ cat runoob.php

<?php echo 1; echo 'runoob'; ?>

$ git diffdiff --cc runoob.phpindex ac60739,b63d7d7…0000000— a/runoob.php+++ b/runoob.php@@@ -1,3 -1,3 +1,4 @@@

<?php +echo 1; + echo 'runoob'; ?>

在 Git 中,我们可以用 git add 要告诉 Git 文件冲突已经解决$ git status -sUU runoob.php$ git add runoob.php$ git status -sM runoob.php$ git commit[master 88afe0e] Merge branch ‘change_site’现在我们成功解决了合并中的冲突,并提交了结果。

Git查看提交历史git log查看历史提交记录git blame -以列表形式查看指定文件的历史修改记录

git log 在使用Git提交了若干更新后,又或者克隆了某个项目,想回顾下提交历史,可以使用git log命令查看。针对我们前一章节的操作,使用git log命令列出历史提交记录如下:$ git logcommit d5e9fc2c811e0ca2b2d28506ef7dc14171a207d9 (HEAD -> master)Merge: c68142b 7774248Author: runoob [email protected]: Fri May 3 15:55:58 2019 +0800

Merge branch ‘change_site’

commit c68142b562c260c3071754623b08e2657b4c6d5bAuthor: runoob [email protected]: Fri May 3 15:52:12 2019 +0800

修改代码

commit 777424832e714cf65d3be79b50a4717aea51ab69 (change_site)Author: runoob [email protected]: Fri May 3 15:49:26 2019 +0800

changed the runoob.php

commit c1501a244676ff55e7cccac1ecac0e18cbf6cb00Author: runoob [email protected]: Fri May 3 15:35:32 2019 +0800

可以用 - - oneline 选项来查看历史记录的简洁的版本

$ git log --oneline$ git log --onelined5e9fc2 (HEAD -> master) Merge branch ‘change_site’c68142b 修改代码7774248 (change_site) changed the runoob.phpc1501a2 removed test.txt、add runoob.php3e92c19 add test.txt3b58100 第一次版本提交

可以看到此项目的开发历史还可以用 - -graph选项,查看历史中什么时候出现了分支,合并。以下为相同的命令,开启了拓扑图选项。

d5e9fc2 (HEAD -> master) Merge branch ‘change_site’|| * 7774248 (change_site) changed the runoob.php

| c68142b 修改代码|/

c1501a2 removed test.txt、add runoob.php

3e92c19 add test.txt

3b58100 第一次版本提交

我们可以更清楚明了地看到何时工作分叉、又何时归并。也可以用 --reverse 参数来逆向显示所有日志。$ git log --reverse --oneline3b58100 第一次版本提交3e92c19 add test.txtc1501a2 removed test.txt、add runoob.php7774248 (change_site) changed the runoob.phpc68142b 修改代码d5e9fc2 (HEAD -> master) Merge branch ‘change_site’

只想查找指定用户的提交日志可以使用命令:git log --author , 例如,比方说我们要找 Git 源码中 Linus 提交的部分:$ git log --author=Linus --oneline -581b50f3 Move ‘builtin-*’ into a ‘builtin/’ subdirectory3bb7256 make “index-pack” a built-in377d027 make “git pack-redundant” a built-inb532581 make “git unpack-file” a built-in112dd51 make “mktag” a built-in

要指定日期,可以执行几个选项:–since 和 --before,但是你也可以用 --until 和 --after。例如,如果我要看 Git 项目中三周前且在四月十八日之后的所有提交,我可以执行这个(我还用了 --no-merges 选项以隐藏合并提交):$ git log --oneline --before={3.weeks.ago} --after={2010-04-18} --no-merges5469e2d Git 1.7.1-rc2d43427d Documentation/remote-helpers: Fix typos and improve language272a36b Fixup: Second argument may be any arbitrary stringb6c8d2d Documentation/remote-helpers: Add invocation section5ce4f4e Documentation/urls: Rewrite to accomodate transport::address00b84e9 Documentation/remote-helpers: Rewrite description03aa87e Documentation: Describe other situations where -z affects git diff77bc694 rebase-interactive: silence warning when no commits rewritten636db2c t3301: add tests to use --format=“%N”

要查看指定文件的修改记录可以使用 git blame 命令git blamegit blame 是以列表形式显示修改记录:

$ git blame README^d2097aa (tianqixin 2020-08-25 14:59:25 +0800 1) # Runoob Git 测试db9315b0 (runoob 2020-08-25 16:00:23 +0800 2) # 菜鸟教程

若达到一个重要的阶段,希望永远记住那个特别的提交快照,可以使用git tag给它打上标签。比如说,我们要为runoob项目发布一个’1.0’版本,可以用git tag -a v1.0 命令给最新一次提交打上(HEAD) ‘v1.0’的标签

-a 选项为“创建一个带注解的标签”。不用-a也是可以执行的,但它不会记录这标签是啥时候打的,谁打的,也不会让你添加个标签的注解。推荐一直创建带注解的标签:$git tag -a v1.0当执行git tag -a ,Git会打开你的编辑器,让你写已经标签注解,就像你给提交写注解一样现在执行git log - - decorate时,我们可以看到我们的标签了:

d5e9fc2 (HEAD -> master) Merge branch ‘change_site’|| * 7774248 (change_site) changed the runoob.php

| c68142b 修改代码|/

c1501a2 removed test.txt、add runoob.php

3e92c19 add test.txt

3b58100 第一次版本提交

如果我们忘了给某个提交打标签,又将它发布了,我们可以给它追加标签。例如,假设我们发布了提交 85fc7e7(上面实例最后一行),但是那时候忘了给它打标签。 我们现在也可以:$ git tag -a v0.9 85fc7e7$ git log --oneline --decorate --graph

d5e9fc2 (HEAD -> master) Merge branch ‘change_site’|| * 7774248 (change_site) changed the runoob.php

| c68142b 修改代码|/

c1501a2 removed test.txt、add runoob.php

3e92c19 add test.txt

3b58100 (tag: v0.9) 第一次版本提交

若要查看所有标签用以下命令:$git tagv0.9v1.0

指定标签信息命令:git tag -a -m “runoob.com标签”

PGP签名标签命令:git tag -s -m “runoob.com标签”

Git Gitee

x2002058@x2002058 ~ % cd Desktop/testx2002058@x2002058 test % lsgit.html style.cssx2002058@x2002058 test % git inithint: Using ‘master’ as the name for the initial branch. This default branch namehint: is subject to change. To configure the initial branch name to use in allhint: of your new repositories, which will suppress this warning, call:hint:hint: git config --global init.defaultBranchhint:hint: Names commonly chosen instead of ‘master’ are ‘main’, ‘trunk’ andhint: ‘development’. The just-created branch can be renamed via this command:hint:hint: git branch -mInitialized empty Git repository in /Users/x2002058/Desktop/test/.git/x2002058@x2002058 test % lsgit.html style.cssx2002058@x2002058 test % ls -a. .DS_Store git.html… .git style.cssx2002058@x2002058 test % git statusOn branch master

No commits yet

Untracked files:(use “git add …” to include in what will be committed).DS_Storegit.htmlstyle.css

nothing added to commit but untracked files present (use “git add” to track)x2002058@x2002058 test % git git.htmlgit: ‘git.html’ is not a git command. See ‘git --help’.x2002058@x2002058 test % git add git.htmlx2002058@x2002058 test % git add style.cssx2002058@x2002058 test % git statusOn branch master

No commits yet

Changes to be committed:(use “git rm --cached …” to unstage)new file: git.htmlnew file: style.css

Untracked files:(use “git add …” to include in what will be committed).DS_Store

x2002058@x2002058 test % git commit -m ‘first commit’[master (root-commit) fd969dc] first commit2 files changed, 15 insertions(+)create mode 100644 git.htmlcreate mode 100644 style.cssx2002058@x2002058 test % git config\usage: git config []

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 use given config file–blob read config from given blob object

Action–get get value: name [value-pattern]–get-all get all values: key [value-pattern]–get-regexp get values for regexp: name-regex [value-pattern]–get-urlmatch get value specific for the URL: section[.var] URL–replace-all replace all matching variables: name value [value-pattern]–add add a new variable: name value–unset remove a variable: name [value-pattern]–unset-all remove all matches: name [value-pattern]–rename-section rename section: old-name new-name–remove-section remove a section: name-l, --list list all–fixed-value use string equality when comparing values to ‘value-pattern’-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–bool-or-str value is --bool or string–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)–show-scope show scope of config (worktree, local, global, system, command)–default with --get, use default value when missing entry

x2002058@x2002058 test % git config -listerror: did you mean --list (with two dashes)?x2002058@x2002058 test %x2002058@x2002058 test % git config --listcredential.helper=osxkeychainuser.name=Orpheususer.email=1446178451@qq.comcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=truecore.ignorecase=truecore.precomposeunicode=truex2002058@x2002058 test % git logcommit fd969dc0fe1603bbe87ad3f33db0ab876a94943c (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

x2002058@x2002058 test % git add .x2002058@x2002058 test % git statusOn branch masterChanges to be committed:(use “git restore --staged …” to unstage)new file: .DS_Storenew file: “git\347\232\204\345\211\257\346\234\254.html”new file: “git\347\232\204\345\211\257\346\234\2542.html”new file: “git\347\232\204\345\211\257\346\234\2543.html”

x2002058@x2002058 test % git commit -m ‘add new files’[master 4c25168] add new files4 files changed, 30 insertions(+)create mode 100644 .DS_Storecreate mode 100644 “git\347\232\204\345\211\257\346\234\254.html”create mode 100644 “git\347\232\204\345\211\257\346\234\2542.html”create mode 100644 “git\347\232\204\345\211\257\346\234\2543.html”x2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test % git logcommit 4c25168231559f76baf45d84ef7916225b04d59e (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

x2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.html

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git add git.htmlx2002058@x2002058 test % git commit -m ‘modify git.html’[master e27027e] modify git.html1 file changed, 1 insertion(+), 1 deletion(-)x2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test % git logcommit e27027e11968a77bd00883c5680fbf1513a2ec0c (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

x2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.html

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git commit -am ‘remodified git.html’[master 8d4d10b] remodified git.html1 file changed, 1 insertion(+), 1 deletion(-)x2002058@x2002058 test % git logcommit 8d4d10b754065739697f5fd4442d54867fd53002 (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

x2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test % git commit -am ‘version 1.0’On branch masternothing to commit, working tree cleanx2002058@x2002058 test % git commit -am ‘version 1.0’[master 65b6e5a] version 1.01 file changed, 1 insertion(+), 1 deletion(-)x2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test % git logcommit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943c:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

:…skipping…commit 65b6e5a8c2518a918ba18bb1c925e9a66c87f0ad (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

~x2002058@x2002058 test % git add git.htmlx2002058@x2002058 test % git commit --amend[master 46a83ae] version 1.0 this version is 1Date: Mon Aug 2 09:06:42 2021 +08001 file changed, 1 insertion(+), 1 deletion(-)x2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.html

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git checkout --git.htmlerror: unknown option `git.html’usage: git checkout []or: git checkout [] [] – …

-b create and checkout a new branch
-B create/reset and checkout a branch
-l create reflog for new branch
–guess second guess ‘git checkout ’ (default)
–overlay use overlay mode (default)
-q, --quiet suppress progress reporting
–recurse-submodules[=]
control recursive updating of submodules
–progress force progress reporting
-m, --merge perform a 3-way merge with the new branch
–conflict

x2002058@x2002058 test % git checkout – git.htmlx2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test %x2002058@x2002058 test %x2002058@x2002058 test %x2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.htmlmodified: style.css

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git checkout – .x2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.html

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git add .x2002058@x2002058 test % git statusOn branch masterChanges to be committed:(use “git restore --staged …” to unstage)modified: git.html

x2002058@x2002058 test % git restore --staged git.htm;error: pathspec ‘git.htm’ did not match any file(s) known to gitx2002058@x2002058 test % git restore --staged git.htmlx2002058@x2002058 test % git reset HEAD git.htmlUnstaged changes after reset:M git.htmlx2002058@x2002058 test % git statusOn branch masterChanges not staged for commit:(use “git add …” to update what will be committed)(use “git restore …” to discard changes in working directory)modified: git.html

no changes added to commit (use “git add” and/or “git commit -a”)x2002058@x2002058 test % git checkout – git.htmlx2002058@x2002058 test % git statusOn branch masternothing to commit, working tree cleanx2002058@x2002058 test % git logcommit 46a83ae1529f9f5bb0775a54d257d19ffcb5e857 (HEAD -> master)Author: Orpheus [email protected]: Mon Aug 2 09:06:42 2021 +0800

version 1.0 this version is 1

commit 8d4d10b754065739697f5fd4442d54867fd53002Author: Orpheus [email protected]: Mon Aug 2 09:02:36 2021 +0800

remodified git.html

commit e27027e11968a77bd00883c5680fbf1513a2ec0cAuthor: Orpheus [email protected]: Mon Aug 2 09:00:30 2021 +0800

modify git.html

commit 4c25168231559f76baf45d84ef7916225b04d59eAuthor: Orpheus [email protected]: Mon Aug 2 08:58:28 2021 +0800

add new files

commit fd969dc0fe1603bbe87ad3f33db0ab876a94943cAuthor: Orpheus [email protected]: Mon Aug 2 08:55:38 2021 +0800

first commit

x2002058@x2002058 test %

以上是我Mac上X2002058实际测试。

猜你喜欢

转载自blog.csdn.net/qq_44682019/article/details/124012096