MIT-Missing Semester_Topic 6:Version Control (Git) 练习题

文章目录

      • 练习一
      • 练习二
      • 练习三
      • 练习四
      • 练习五
      • 练习六
      • 练习七

本 Topic 的 MIT 讲解网页(练习题未给解答)

练习一

若还没有 Git 的相关经验,阅读 Pro Git 的前几章或诸如 Learn Git Branching 的相关教程,并在学习的同时从 Git 的数据模型(data model)的角度思考各 Git 命令。

老师非常建议阅读 Pro Git。

练习二

clone 该课程(Missing Semester)网站的仓库,随后:

  1. 以图的形式展现其版本历史
  2. 运用 git log 加一个参数,找到修改 README.md 的最后一人
  3. 运用 git blamegit show 得到 _config.ymlcollections: 这一行最后一次修改的 commit 信息

第 1、3 小题在 lecture 中演示过,而第 2 小题据提示比较简单。

  1. git clone <URL> <folder>*(必备基础技能)*克隆课程仓库:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise$ git clone https://github.com/missing-semester/missing-semester missing-semester
    Cloning into 'missing-semester'...
    remote: Enumerating objects: 2344, done.
    remote: Counting objects: 100% (1487/1487), done.
    remote: Compressing objects: 100% (543/543), done.
    remote: Total 2344 (delta 980), reused 964 (delta 941), pack-reused 857
    Receiving objects: 100% (2344/2344), 15.61 MiB | 1.28 MiB/s, done.
    Resolving deltas: 100% (1392/1392), done.
    
  2. 不妨运用 Topic 5 所讲解的 别名 (alias) 知识,简化 git log 的相关图示法命令:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/test/demo$ alias gl='git log --all --graph --decorate'
    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/test/demo$ alias gl1='gl --oneline'
    

    **提示:**可以在配置文件 ~/.bashrc 中设定默认的 alias

    • gl:包含详细 commit 的信息

      cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ gl > gl_res.log
      cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ vim gl_res.log
      

      结果极长,共 4218 行。

    • gl1:缩略信息,每个 commit 仅一行

      *   d38f585 (HEAD -> master, origin/master, origin/HEAD) Merge branch 'alexandr-gnrk/update-jupyter-binding'
      |\
      | * f600f32 Update Vim binding for Jupyter
      |/
      * 2253e4e Switch recommended app to Rectangle
      * 18ee93c Ignore Reddit URLs when checking links
      *   2ab1b78 Merge branch 'alkock/master'
      |\
      | * 98d90f8 added german translation
      |/
      * bd75a78 Fix broken links
      *   7330a25 Merge branch 'fipachu/git-aliases'
      |\
      | * 6fc734b Add more useful overview of Git aliases
      |/
      *   f45234f Merge branch 'Nikitaz1410/patch-2'
      ...
      

      部分较新的历史如上,共 885 行。

    **提示:**当 git log 等其它 git 命令的信息较长时会显示前一部分信息并自动进入某种 “交互” 模式,上下移动方法同 Vim,H 键显示帮助,Q 键退出。

  3. 考虑使用 Topic 2 提及的 tldr 工具查询所需用法:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ tldr git log...Show a history of commits.More information: https://git-scm.com/docs/git-log....- Show the history of a particular file or directory, including differences:git log -p path/to/file_or_directory...
    

    由此得知 git log -p + 文件/文件夹

    后来发现不应该如上加上 -p flag,其会显示所有 “differences”,直接加文件即可:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ git log README.md
    commit 9ef9db72211fefc00caaa7133b35dda4a99acccf
    Author: Anish Athalye <me@anishathalye.com>
    Date:   Thu Oct 27 20:28:41 2022 -0400Add Docker setup for easier development
    ...
    

    因此显然是授课老师 Anish Athalye 最后修改了 README.md

  4. lecture 中演示了。先 git blame + 文件并找到目标信息对应的 commit,随后 git show <commit> 得到其相关信息:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ git blame _config.yml
    ...
    a88b4eac (Anish Athalye 2020-01-17 15:26:30 -0500 18) collections:
    a88b4eac (Anish Athalye 2020-01-17 15:26:30 -0500 19)   '2019':
    ...
    

    ⇒ \Rightarrow commit 哈希值为 a88b4eac

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ git show a88b
    commit a88b4eac326483e29bdac5ee0a39b180948ae7fc
    Author: Anish Athalye <me@anishathalye.com>
    Date:   Fri Jan 17 15:26:30 2020 -0500Redo lectures as a collection
    ...
    

    所以对应 commit 的信息为 “Redo lectures as a collection”

练习三

为应对误将不应被 Git 管理的内容,如某大文件或敏感信息,commit 的情况,学习 Github 上的相关文章,随后模拟上述情形下删除目标文件。

学习文章知,可以使用两种工具(均需安装):

  • git filter-repo
  • BFG Repo-Cleaner

练习四

修改某仓库中的文件,随后依次 git stashgit log --all --onelinegit stash pop 巩固 git stash 的技能,并思考其可能适用于在何种情况。

stash vt. 藏匿; 隐藏; 存放; 贮藏(百度翻译)

lecture 中也演示过 git stash,其可 “隐藏” 所做的修改,并以 git stash pop 恢复。

  1. 修改 README.md 之后 git stash

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/test_git_stash$ echo '**REMOVED**' > README.md
    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/test_git_stash$ git status
    On branch master
    Your branch is up to date with 'origin/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:   README.mdno changes added to commit (use "git add" and/or "git commit -a")
    
  2. git log

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/test_git_stash$ git log --all --oneline
    7fca419 (refs/stash) WIP on master: d38f585 Merge branch 'alexandr-gnrk/update-jupyter-binding'
    088c991 index on master: d38f585 Merge branch 'alexandr-gnrk/update-jupyter-binding'
    d38f585 (HEAD -> master, origin/master, origin/HEAD) Merge branch 'alexandr-gnrk/update-jupyter-binding'`
    ...
    

    可以发现在 HEAD commit 之上多了两条 commit!且最后一条为 refs/stash

  3. git stash pop 恢复:

    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/test_git_stash$ git stash pop
    On branch master
    Your branch is up to date with 'origin/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:   README.mdno changes added to commit (use "git add" and/or "git commit -a")
    Dropped refs/stash@{0} (7fca419c92d8bff936036a4ca32b277d11c1849a)
    cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/test_git_stash$ git log --all --oneline | head -10
    d38f585 Merge branch 'alexandr-gnrk/update-jupyter-binding'
    ...
    

    直接跳出了 README.md 被更新的提示,且此时 git log 已无之前新增的 commit 记录。

git stash 应该在修改文件后又想看其之前的内容时非常有用。若无 git stash,恐怕只能先将文件存在别处,随后 git checkout -- <file> 丢弃修改。

练习五

在 Git 的配置文件 ~/.gitconfig 中创建 alias,以便使用 git graph 便能得到 git log --all --graph --decorate --oneline 的结果。

.gitconfig 文件中加入:

[alias]graph = log --all --graph --decorate --oneline

测试如下:

cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$ diff <(git graph) <(git log --all --graph --decorate --oneline)
cowbby@LAPTOP-UD6KDALFP:~/Missing Semester/6_Version Control(git)/exercise/missing-semester$

可见两者输出完全一样。

练习六

You can define global ignore patterns in ~/.gitignore_global after running git config --global core.excludesfile ~/.gitignore_global. Do this, and set up your global gitignore file to ignore OS-specific or editor-specific temporary files, like .DS_Store.

练习七

Fork the repository for the class website, find a typo or some other improvement you can make, and submit a pull request on GitHub (you may want to look at this). Please only submit PRs that are useful (don’t spam us, please!). If you can’t find an improvement to make, you can skip this exercise.
u may want to look at this). Please only submit PRs that are useful (don’t spam us, please!). If you can’t find an improvement to make, you can skip this exercise.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/671618.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大型装备制造企业案例分享——通过CRM系统管理全球业务

本期&#xff0c;小Z为大家带来的CRM管理系统客户案例是某大型装备制造企业运用Zoho CRM管理全球业务的过程分享。该企业是创业板上市公司&#xff0c;业务遍及100多个国家和地区&#xff0c;合作伙伴超百位&#xff0c;拥有覆盖全球的销售和服务网络。截止目前&#xff0c;相继…

7.electron之渲染线程发送事件,主进程监听事件

如果可以实现记得点赞分享&#xff0c;谢谢老铁&#xff5e; Electron是一个使用 JavaScript、HTML 和 CSS 构建桌面应用程序的框架。 Electron 将 Chromium 和 Node.js 嵌入到了一个二进制文件中&#xff0c;因此它允许你仅需一个代码仓库&#xff0c;就可以撰写支持 Windows、…

【漏洞复现】电信网关配置管理系统SQL注入漏洞

Nx01 产品简介 电信网关配置管理系统是一个用于管理和配置电信网络中网关设备的软件系统。它可以帮助网络管理员实现对网关设备的远程监控、配置、升级和故障排除等功能&#xff0c;从而确保网络的正常运行和高效性能。 Nx02 漏洞描述 电信网关配置管理系统存在SQL注入漏洞,攻…

jmeter二次开发函数-生成身份证号

代码参考这个 java 随机生成身份证代码 Java的身份证号码工具类 pom文件添加 <dependency><groupId>org.apache.jmeter</groupId><artifactId>ApacheJMeter_core</artifactId><version>5.4.1</version></dependency><d…

annaconda如何切换当前python环境

annaconda默认的python环境是base&#xff1a; 把各种项目的依赖都安装到base环境中不是一个好的习惯&#xff0c;比如说我们做爬虫项目和做自动化测试项目等所需要的依赖是不一样的&#xff0c;我们可以将为每个项目创建自己的环境&#xff0c;在各自的环境中安装自己的依赖&…

Android 11 访问 Android/data/或者getExternalCacheDir() 非root方式

前言&#xff1a; 需求要求安装三方应用ExternalCacheDir()下载下来的apk文件。 getExternalCacheDir() : /storage/emulated/0/Android/data/com../cache/ 获取访问权限 如果手机安卓版本为Android10的时候,可以在AndroidManifest.xml中添加下列代码 android:requestLegacyExt…

Leetcode 30天高效刷数据结构和算法 Day1 两数之和 —— 无序数组

两数之和 —— 无序数组 给定一个整数数组 nums 和一个整数目标值 target&#xff0c;请你在该数组中找出 和为目标值 target 的那 两个 整数&#xff0c;并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是&#xff0c;数组中同一个元素在答案里不能重复出现…

JAVA原型模式详解

原型模式 1 原型模式介绍 定义: 原型模式(Prototype Design Pattern)用一个已经创建的实例作为原型&#xff0c;通过复制该原型对象来创建一个和原型对象相同的新对象。 西游记中的孙悟空 拔毛变小猴,孙悟空这种根据自己的形状复制出多个身外化身的技巧,在面向对象软件设计领…

【Transformer-Hugging Face 06/10】 数据预处理实例

目录 一、说明二、自然语言处理2.1 Pad2.2 截断2.3 构建张量 三、TensorFlow四、处理语音五、计算机视觉六、填充七、Multimodal 一、说明 在数据集上训练模型之前&#xff0c;需要将其预处理为预期的模型输入格式。无论您的数据是文本、图像还是音频&#xff0c;都需要将它们…

Leetcode第383场周赛

Leetcode第383场周赛 本人水平有限&#xff0c;只做前3道。 一、边界上的蚂蚁 边界上有一只蚂蚁&#xff0c;它有时向 左 走&#xff0c;有时向 右 走。 给你一个 非零 整数数组 nums 。蚂蚁会按顺序读取 nums 中的元素&#xff0c;从第一个元素开始直到结束。每一步&#…

C#中实现串口通讯(使用SerialPort类)

仅作自己学习使用 1 准备部份 需要两个调试软件commix和Virtual Serial Port Driver&#xff0c;分别用于监视串口和创造虚拟串口。 第一个软件是这样的&#xff1a; 资源在这里&#xff1a;免费下载&#xff1a;Commix 也可以前往官网下载&#xff1a;Bwsensing— Attitude…

CSS综合案例4

CSS综合案例4 1. 综合案例 我们来做一个静态的轮播图。 2. 分析思路 首先需要加载一张背景图进去需要4个小圆点&#xff0c;设置样式&#xff0c;并用定位和平移调整位置添加两个箭头&#xff0c;也是需要用定位和位移进行调整位置 3. 代码演示 html文件 <!DOCTYPE htm…

几个好用的 iphone 手机模板贴图样机

整理了几个好用的 iphone 手机模板贴图&#xff0c;分享一下。 关注订阅号「设计师工作日常」&#xff0c;发送关键词 iphone mockup ,获取下载链接。 [1] 原文阅读 我是 Just&#xff0c;这里是「设计师工作日常」&#xff0c;求点赞求关注&#xff01;

MongoDB从入门到实战之.NET Core使用MongoDB开发ToDoList系统(1)-后端项目框架搭建

前言&#xff1a; 前面的四个章节我们主要讲解了MongoDB的相关基础知识&#xff0c;接下来我们就开始进入使用.NET7操作MongoDB开发一个ToDoList系统实战教程。本章节主要介绍的是如何快熟搭建一个简单明了的后端项目框架。 MongoDB从入门到实战的相关教程 MongoDB从入门到实战…

算法训练营day23(补),回溯3

import ( "sort" ) 39. 组合总和 func combinationSum(candidates []int, target int) [][]int { //存储全部集合 result : make([][]int, 0) if len(candidates) 0 { return result } sort.Ints(candidates) //排序后面做剪枝 //存储单次集合 path : make([]int…

RBAC权限控制系统-手撸RBAC

手撸RBAC 一、概述 1、什么是RBAC RBAC&#xff08;Role-Based Access Control&#xff09;是一种访问控制机制&#xff0c;它基于角色的概念&#xff0c;将权限授予特定的角色&#xff0c;而不是直接授予个体用户。 这种模型允许管理员根据用户的角色来管理他们的权限&…

服务器出现问题该怎么办?

在我们日常使用服务器的过程中&#xff0c;经常会有遇到服务器出现各种各样问题&#xff0c;服务器出错的原因有很多种&#xff0c;常见的包括系统问题、软件问题、硬件问题和网络问题。今天德迅云安全就来介绍几种比较常见的情况。 一、 服务器出现蓝屏、死机可能的原因&#…

QGIS编译(跨平台编译)之四十八:pixman编译(Windows、Linux、MacOS环境下编译)

文章目录 一、pixman介绍二、pixman下载三、Linux下编译四、MacOS下编译五、Windows下编译一、pixman介绍 Pixman 是一个开源的图形库,它提供了底层像素操作功能,包括像素格式转换、图像合成、图像缩放、图像旋转等多种操作。Pixman 主要被用作 Cairo 图形库的后端,支持 Ca…

Arcgis使用过程中常见问题解决方法

Arcgis无法连接数据库/数据库连接或创建失败解决方法 最近在使用arcgis过程中出现无法连接数据库或者是无法创建数据库。连接到数据库失败&#xff1b;无法创建新的数据库&#xff0c;权限被拒绝&#xff08;如下图&#xff09;。 出现这个原因是你所用的电脑系统文件dao360.…

C++多线程学习[六]: 多线程之间的同步

一、同步问题 实际开发场景中有很多需要同步的情况&#xff0c;例如&#xff0c;音频和视频的同步输出、或者通讯能够第一时间同步接受处理… 二、多线程同步demo 可以看到cond可以阻塞等待&#xff08;wait&#xff09;可以通知一个线程(notify_one)也可以通知所有的线程&am…