0
点赞
收藏
分享

微信扫一扫

【JUC进阶】09. 关于锁升级

小美人鱼失去的腿 2023-07-04 阅读 37
git学习

查看提交历史

查看提交历史

在提交了若干更新,又或者克隆了某个项目之后,你也许想回顾下提交历史。 完成这个任务最简单而又有效的工具是 git log 命令

$ git log
commit 01a47b58bc81fbf7968cbcf6db266eee6bd88e6a (HEAD -> master, origin/master)
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:18:48 2023 +0800

    提交REDEME文件

commit 8685043211cf7702e736bb378abec0a23c0de225
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:15:07 2023 +0800

    提交REDEME文件

commit e1599dc76248e9ef5f57354640f2c071042b17c9
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 17:47:16 2023 +0800

    7月3号学习

不传入任何参数的默认情况下,git log 会按时间先后顺序列出所有的提交,最近的更新排在最上面。 正如你所看到的,这个命令会列出每个提交的 SHA-1 校验和、作者的名字和电子邮件地址、提交时间以及提交说明。

git log 有许多选项可以帮助你搜寻你所要找的提交, 下面我们会介绍几个最常用的选项。

其中一个比较有用的选项是 -p 或 --patch ,它会显示每次提交所引入的差异(按 补丁 的格式输出)。 你也可以限制显示的日志条目数量,例如使用 -2 选项来只显示最近的两次提交

$ git log -p -2
commit 01a47b58bc81fbf7968cbcf6db266eee6bd88e6a (HEAD -> master, origin/master)
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:18:48 2023 +0800

    提交REDEME文件

diff --git a/README b/README
index 74e5e69..31996f0 100644
--- a/README
+++ b/README
@@ -1 +1,2 @@
 My project
+change filename

commit 8685043211cf7702e736bb378abec0a23c0de225
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:15:07 2023 +0800

    提交REDEME文件

diff --git a/README b/README
new file mode 100644
index 0000000..74e5e69
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+My project

你也可以为 git log 附带一系列的总结性选项。 比如你想看到每次提交的简略统计信息,可以使用 --stat 选项:

git log --stat
commit 01a47b58bc81fbf7968cbcf6db266eee6bd88e6a (HEAD -> master, origin/master)
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:18:48 2023 +0800

    提交REDEME文件

 README | 1 +
 1 file changed, 1 insertion(+)

commit 8685043211cf7702e736bb378abec0a23c0de225
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 18:15:07 2023 +0800

    提交REDEME文件

 README | 1 +
 1 file changed, 1 insertion(+)

commit e1599dc76248e9ef5f57354640f2c071042b17c9
Author: zhaozhiqing1 <1652918084@qq.com>
Date:   Mon Jul 3 17:47:16 2023 +0800

    7月3号学习

 Abstract_factoryy/AbstractFactory.hpp       |  21 ++++++
 Abstract_factoryy/AbstractProduct.hpp       |  23 +++++++
 Abstract_factoryy/ConcreteFactory.hpp       |  39 +++++++++++
 Abstract_factoryy/ConcreteProduct.hpp       |  38 +++++++++++
 Abstract_factoryy/main.cpp                  |  35 ++++++++++
 Adapter/Adapter.hpp                         |  16 +++++
 Adapter/Client.hpp                          |  24 +++++++
 Adapter/ClientInterface.hpp                 |   9 +++
 Adapter/Service.hpp                         |  14 ++++
 Adapter/main.cpp                            |  26 ++++++++
 Bridge/Abstraction.hpp                      |  24 +++++++
 Bridge/ConcreteImplementation.hpp           |  29 ++++++++
 Bridge/Implementation.hpp                   |  20 ++++++
 Bridge/RefinedAbstraction.hpp               |  36 ++++++++++
 Bridge/main.cpp                             |  22 ++++++
 Builder/Builder.hpp                         |  27 ++++++++
 Builder/ConcreteBuilder.hpp                 |  40 +++++++++++
 Builder/Director.hpp                        |  32 +++++++++
 Builder/Product.hpp                         |  28 ++++++++
 Builder/main.cpp                            |  32 +++++++++
 Chain_of_Responsibility/BaseHandler.hpp     |  44 ++++++++++++
 Chain_of_Responsibility/ConcreteHandler.hpp |  35 ++++++++++
 Chain_of_Responsibility/Handler.hpp         |  22 ++++++
 Chain_of_Responsibility/main.cpp            |  24 +++++++
 Command/Command.hpp                         |   8 +++
 Command/ConcreteCommand.hpp                 |  56 ++++++++++++++++
 Command/Invoker.hpp                         |  32 +++++++++
 Command/Receiver.hpp                        |  31 +++++++++
 Command/main.cpp                            |  31 +++++++++
 Composite/Component.hpp                     |  17 +++++
 Composite/Composite.hpp                     |  40 +++++++++++
 Composite/Leaf.hpp                          |  43 ++++++++++++
 Composite/main.cpp                          |  38 +++++++++++
 Decorator/BaseDecorator.hpp                 |  28 ++++++++
 Decorator/Component.hpp                     |  20 ++++++
 Decorator/ConcreteComponent.hpp             |  30 +++++++++
 Decorator/ConcreteDecorator.hpp             |  41 ++++++++++++
 Decorator/main.cpp                          |  29 ++++++++
 Facade/Facade.hpp                           |  48 +++++++++++++
 Facade/SubSystem.hpp                        |  54 +++++++++++++++
 Facade/main.cpp                             |  15 +++++
 Factory_mothod/ConcreteCreator.hpp          |  32 +++++++++
 Factory_mothod/ConcreteProduct.hpp          |  35 ++++++++++
 Factory_mothod/Create.hpp                   |  13 ++++
 Factory_mothod/Product.hpp                  |  17 +++++
 Factory_mothod/main.cpp                     |  22 ++++++
 Flyweight/Client.hpp                        |  36 ++++++++++
 Flyweight/Context.hpp                       |  30 +++++++++
 Flyweight/Flyweight.hpp                     |  26 ++++++++
 Flyweight/FlyweightFactory.cpp              |  12 ++++
 Flyweight/FlyweightFactory.hpp              |  53 +++++++++++++++
 Flyweight/main.cpp                          |  23 +++++++
 Iterator/Collection.hpp                     |  23 +++++++
 Iterator/ConcreteCollection.hpp             |  31 +++++++++
 Iterator/ConcreteIterator.hpp               |  53 +++++++++++++++
 Iterator/Iterator.hpp                       |  22 ++++++
 Iterator/main.cpp                           |  18 +++++
 Mediator/Component.hpp                      | 100 ++++++++++++++++++++++++++++
 Mediator/ConcreteMediator.hpp               |  55 +++++++++++++++
 Mediator/Mediator.hpp                       |  24 +++++++
 Mediator/main.cpp                           |  47 +++++++++++++
 Memento/Caretaker.hpp                       |  33 +++++++++
 Memento/Memento.hpp                         |  39 +++++++++++
 Memento/Originator.hpp                      |  58 ++++++++++++++++
 Memento/main.cpp                            |  25 +++++++
 Observer/ConcreteSubscriber.hpp             |  30 +++++++++
 Observer/Publisher.hpp                      |  44 ++++++++++++
 Observer/Subscriber.hpp                     |  18 +++++
 Observer/main.cpp                           |  19 ++++++
 Observer/tempCodeRunnerFile                 | Bin 0 -> 1884592 bytes
 Observer/tempCodeRunnerFile.hpp             |   9 +++
 Proxy/Client.hpp                            |  37 ++++++++++
 Proxy/Proxy.hpp                             |  45 +++++++++++++
 Proxy/Service.hpp                           |  27 ++++++++
 Proxy/ServiceInterface.hpp                  |  19 ++++++
 Proxy/main.cpp                              |  16 +++++
 Proxy/proxy                                 | Bin 0 -> 97984 bytes
 class_wrapper-1.py                          |  17 +++++
 class_wrapper-2.py                          |  37 ++++++++++
 class_wrapper-3.py                          |  20 ++++++
 class_wrapper.py                            |  27 ++++++++
 demo1.cpp                                   |   9 +++
 func_wrapper-1.py                           |  35 ++++++++++
 func_wrapper-2.py                           |  38 +++++++++++
 func_wrapper-3.py                           |  33 +++++++++
 func_wrapper.py                             |  25 +++++++
 list_1.py                                   |  12 ++++
 map_demo.py                                 |   6 ++
 output/demo                                 | Bin 0 -> 66840 bytes
 set_demo.py                                 |  15 +++++
 tuple_demo1.py                              |  14 ++++
 91 files changed, 2600 insertions(+)

Git 基础 - 撤消操作

撤消操作

在任何一个阶段,你都有可能想要撤消某些操作。 这里,我们将会学习几个撤消你所做修改的基本工具。 注意,有些撤消操作是不可逆的。 这是在使用 Git 的过程中,会因为操作失误而导致之前的工作丢失的少有的几个地方之一。

git commit --amend

这个命令会将暂存区中的文件提交。 如果自上次提交以来你还未做任何修改(例如,在上次提交后马上执行了此命令), 那么快照会保持不变,而你所修改的只是提交信息

取消暂存的文件

接下来的两个小节演示如何操作暂存区和工作目录中已修改的文件。 这些命令在修改文件状态的同时,也会提示如何撤消操作。 例如,你已经修改了两个文件并且想要将它们作为两次独立的修改提交, 但是却意外地输入 git add * 暂存了它们两个。如何只取消暂存两个中的一个呢? git status 命令提示了你:

$ git add *
$ git status 
位于分支 master
您的分支与上游分支 'origin/master' 一致。

要提交的变更:
  (使用 "git restore --staged <文件>..." 以取消暂存)
	删除:     README
	新文件:   demo

在 “Changes to be committed” 文字正下方,提示使用 git restore --staged <文件>..." 以取消暂存)。 所以,我们可以这样来取消暂存 demo 文件:

$ git restore --staged demo
$ git status 
位于分支 master
您的分支与上游分支 'origin/master' 一致。

要提交的变更:
  (使用 "git restore --staged <文件>..." 以取消暂存)
	删除:     README

未跟踪的文件:
  (使用 "git add <文件>..." 以包含要提交的内容)
	demo

撤消对文件的修改

如果你并不想保留对 demo 文件的修改怎么办? 你该如何方便地撤消修改——将它还原成上次提交时的样子(或者刚克隆完的样子,或者刚把它放入工作目录时的样子)? 幸运的是,git status 也告诉了你应该如何做。 在最后一个例子中,未暂存区域是这样:

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:   CONTRIBUTING.md

它非常清楚地告诉了你如何撤消之前所做的修改。 让我们来按照提示执行

$ git checkout -- CONTRIBUTING.md
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    renamed:    README.md -> README

远程仓库的使用

远程仓库的使用

为了能在任意 Git 项目上协作,你需要知道如何管理自己的远程仓库远程仓库是指托管在因特网或其他网络中的你的项目的版本库。 你可以有好几个远程仓库,通常有些仓库对你只读,有些则可以读写。 与他人协作涉及管理远程仓库以及根据需要推送或拉取数据。 管理远程仓库包括了解如何添加远程仓库、移除无效的远程仓库、管理不同的远程分支并定义它们是否被跟踪等等。

查看远程仓库

果想查看你已经配置的远程仓库服务器,可以运行 git remote 命令。 它会列出你指定的每一个远程服务器的简写。

$ git remote 
origin

你也可以指定选项 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL。​​​​​​​​​​​​​​

git remote -v
origin	https://gitee.com/zhaozhiqing1/cpp_learn.git (fetch)
origin	https://gitee.com/zhaozhiqing1/cpp_learn.git (push)

添加远程仓库

我们在之前的章节中已经提到并展示了 git clone 命令是如何自行添加远程仓库的, 不过这里将告诉你如何自己来添加它。 运行 git remote add <shortname> <url> 添加一个新的远程 Git 仓库,同时指定一个方便使用的简写

$ git remote
origin
$ git remote add pb https://github.com/paulboone/ticgit
$ git remote -v

现在你可以在命令行中使用字符串 pb 来代替整个 URL。 例如,如果你想拉取 Paul 的仓库中有但你没有的信息,可以运行 git fetch pb

git fetch pb
remote: Counting objects: 43, done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 43 (delta 10), reused 31 (delta 5)
Unpacking objects: 100% (43/43), done.
From https://github.com/paulboone/ticgit
 * [new branch]      master     -> pb/master
 * [new branch]      ticgit     -> pb/ticgit

从远程仓库中抓取与拉取

就如刚才所见,从远程仓库中获得数据,可以执行:

$ git fetch <remote>

这个命令会访问远程仓库,从中拉取所有你还没有的数据。 执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。

推送到远程仓库

当你想分享你的项目时,必须将其推送到上游。 这个命令很简单:git push <remote> <branch> 当你想要将 master 分支推送到 origin 服务器时(再次说明,克隆时通常会自动帮你设置好那两个名字), 那么运行这个命令就可以将你所做的备份到服务器:

$ git push origin master

只有当你有所克隆服务器的写入权限,并且之前没有人推送过时,这条命令才能生效。 当你和其他人在同一时间克隆,他们先推送到上游然后你再推送到上游,你的推送就会毫无疑问地被拒绝.

查看某个远程仓库

如果想要查看某一个远程仓库的更多信息,可以使用 git remote show <remote> 命令。 如果想以一个特定的缩写名运行这个命令,例如 origin,会得到像下面类似的信息:

$ git remote show origin 
Username for 'https://gitee.com': zhaozhiqing1
Password for 'https://zhaozhiqing1@gitee.com': 
* 远程 origin
  获取地址:https://gitee.com/zhaozhiqing1/cpp_learn.git
  推送地址:https://gitee.com/zhaozhiqing1/cpp_learn.git
  HEAD 分支:master
  远程分支:
    master 已跟踪
  为 'git pull' 配置的本地分支:
    master 与远程 master 合并
  为 'git push' 配置的本地引用:
    master 推送至 master (可快进)

远程仓库的重命名与移除

你可以运行 git remote rename 来修改一个远程仓库的简写名。 例如,想要将 pb 重命名为 paul,可以用 git remote rename 这样做:

$ git remote rename pb paul
$ git remote
origin
paul

如果因为一些原因想要移除一个远程仓库——你已经从服务器上搬走了或不再想使用某一个特定的镜像了, 又或者某一个贡献者不再贡献了——可以使用 git remote remove 或 git remote rm :

$ git remote remove paul
$ git remote
origin
举报

相关推荐

0 条评论