git学习--githug20-40关

来源:互联网 发布:mac 开机密码设置 编辑:程序博客网 时间:2024/05/17 21:48

20-40关的记录
21、
Name: reset
Level: 21
Difficulty: **
There are two files to be committed. The goal was to add each file as a separate commit, however both were added by accident. Unstage the file to_commit_second.rb using the reset command (don’t commit anything).
Answer:git reset HEAD && git add to_commit_first.rb
22、
Name: reset_soft
Level: 22
Difficulty: **
You committed too soon. Now you want to undo the last commit, while keeping the index.
Answer:git reset –soft HEAD~
注:git commit级别的撤销
git reset
–soft : staged snapshot 和 working directory 都未被改变 (建议在命令行执行后,再输入 git status 查看状态)
–mixed: staged snapshot 被更新, working directory 未被更改。【这是默认选项】(建议同上)
–hard : staged snapshot 和 working directory 都将回退。
注:git reset 用于撤销未被提交到远端的改动, –hard 很危险,它会直接回退你之前所有的修改,使用前,可以事先保存 commit id.

git checkout     到目前为止我们接触过最多的命令之一,当执行git checkout branch_name 时,会切换HEAD到其他分支去,并且更新当前的working directory,     因为会覆盖当前的working directory,所以在切换前如果有未提交的修改,git将强制你提交或者放弃修改.git checkout commitId,     也可以根据提交的某一次commitId来进行.git revert    注:git revert 命令通过创建一次新的 commit 来撤销一次 commit 所做出的修改。相比git reset,它会修改commit history。

23、
Name: checkout_file
Level: 23
Difficulty: *
A file has been modified, but you don’t want to keep the modification. Checkout the config.rb file from the last commit.
Answer: git checkout config.rb
注:
file 级别的撤销
git reset 和 git checkout 也可以接受一个文件名来实现单个文件上的撤销操作
git reset 当它的参数为文件路径时,他会更新staged snapshot去匹配某次的commit, 此时的–soft、–mixed、–hard参数不起作用
git checkout 当它的参数为文件路径是,他会更新working directory 来匹配某次commit
24、
Name: remote
Level: 24
Difficulty: **
This project has a remote repository. Identify it.
Answer:git remote show
25、
Name: remote_url
Level: 25
Difficulty: **
The remote repositories have a url associated to them. Please enter the url of remote_location.
Answer:git remote -v | grep remote_location
注:打开git remote 的帮助第一个便是show remote url的参数
-v, –verbose
Be a little more verbose and show remote url after name. NOTE: This must be placed between remote and
subcommand.
26、
Name: pull
Level: 26
Difficulty: **
You need to pull changes from your origin repository.
Answer: git pull origin master
27、
Name: remote_add
Level: 27
Difficulty: **
Add a remote repository called origin with the url https://github.com/githug/githug
Answer:git remote add origin https://github.com/githug/githug
注: git remote add [-t ] [-m ] [-f] [–[no-]tags] [–mirror=

0 0