missing课程作业_version-control

missing_version-control

课程地址:https://missing.csail.mit.edu/2020/version-control/
学习git_branch:https://learngitbranching.js.org/?locale=zh_CN
更好的答案:https://mit-6null-notes.book.triplez.cn/lec/06-version-control-git/

Q1

Question

If you don’t have any past experience with Git, either try reading the first couple chapters of Pro Git or go through a tutorial like Learn Git Branching. As you’re working through it, relate Git commands to the data model.

Solution

finish
在这里插入图片描述

Q2

Question

Clone the repository for the class website.

  1. Explore the version history by visualizing it as a graph.
  2. Who was the last person to modify README.md? (Hint: use git log with an argument).
  3. What was the commit message associated with the last modification to the collections: line of _config.yml? (Hint: use git blame and git show).

Solution

  1. git log --all --graph --decorate --oneline
  2. git log README.md
  3. git blame _config.yml | grep collections ; git show a88b4eac

Q3

Question

One common mistake when learning Git is to commit large files that should not be managed by Git or adding sensitive information. Try adding a file to a repository, making some commits and then deleting that file from history (you may want to look at this).

Solution

Todo
git-filter-repo不在ubuntu20.04lts资源包中
可以尝试安装jar工具bfg

$ bfg --delete-files YOUR-FILE-WITH-SENSITIVE-DATA
$ bfg --replace-text passwords.txt
$ git push --force

Q4

Question

Clone some repository from GitHub, and modify one of its existing files. What happens when you do git stash? What do you see when running git log --all --oneline? Run git stash pop to undo what you did with git stash. In what scenario might this be useful?

Answer

$ echo 'Hello wordl' > modify
$ git add modify
$ git stash
Saved working directory and index state WIP on main: 9e6bd59 Delete snow directory
$ git commit
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
$ git stash pop
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   modify

Dropped refs/stash@{0} (7168746ee44d2e2d7dd8632d80862001ebba2af2)
$ git commit -m 'test the function of "git stash"'
[main fd35c4c] test the function of "git stash"
 1 file changed, 1 insertion(+)
 create mode 100644 modify
$ git log --oneline
fd35c4c (HEAD -> main) test the function of "git stash"

用来将staging area中内容暂时放到堆栈中
stash pop重新加入到stagin area

Q5

Question

Like many command line tools, Git provides a configuration file (or dotfile) called ~/.gitconfig. Create an alias in ~/.gitconfig so that when you run git graph, you get the output of git log --all --graph --decorate --oneline. Information about git aliases can be found here.

Answer

在~/.gitconfig中修改

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

获得结果

$ git graph
* fd35c4c (HEAD -> main) test the function of "git stash"
* 9e6bd59 (origin/main, origin/HEAD) Delete snow directory

Q6

Question

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.

Solution

设置全局ignore文件

$ echo ".DS_Store" >> ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global

检查效果

$ touch .DS_Store
$ ls -a
.         ..        .DS_Store .git
$ git status                                                  
On branch main                                                                            
Your branch is ahead of 'origin/main' by 1 commit.                                             
(use "git push" to publish your local commits)                                                                                                                                          
nothing to commit, working tree clean

Q7

Question

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).

Solution

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值