Git && GitHub

本篇日志算学习的心得吧。

来自优达学院优秀的Git和GitHub课程,学习网站: https://classroom.udacity.com/courses/ud775 ,本课程是绝对学习Git和GitHub操作不可多得的优秀的视频教程。采用了先进的网络慕课格式, 教学与联系,思考并重,技术领先。且英文教学,中文字幕,学习技术性领先的技术,还是跟上国际步伐是好的,特别是GitHub社区是英文的,相信这个教程将很好的提供帮助。

通过课程:
学会了本地版本比较,克隆,提交历史操作记录形成版本控制
学会Git
学会GitHub
这里写图片描述

Git的操作


// 初始化仓库
git init

// 查看仓库状态
git status

// 增加新文件到待定区
git add xxxx

// 删除待定区文件
git reset xxxx

// 提交信息
git commit -m "Commit message"
git commit

// 哎哟我的天,退出Vim用了贼久。
// 呐,填写好信息之后呢,先ESC,光标在下方了,然后wq,回车,回到git bash

// 检查工作区间与待定区文件修改
git diff
// 检查待定区和仓库文件修改
git diff --staged

// 撤销工作区间,和待定区文件的修改,将不可逆,切记切记
git reset --hard

// 分支
// 查看分支(带*号说明在该分支上)
git branch
// 新建分支
git branch xxxx
//(xxxx分支名称)
// 到分支上
git checkout xxxx

// 视图查看分支区别
git log --graph --oneline xxxx yyyy
//(--oneline使输出更短更容易阅读 xxxx yyyy 比较分支)

// 可访问性:无法访问其他分支的commit

git checkout -b new_branch_name

// 分支合并
git merge xxxx yyyy

// 查看与父级的区别
git show

// 删除分支
git branch -d xxxx

git log -n 1

GitHub操作


// 查看远程
git remote
git remote -v

// 远程连接GitHub
git remote add origin git@github.com:wuzhilaona/reflections.git
// git remote add xxx(名称,只有一个远程代码库,使用origin) yyy(地址)

// 向远程代码库发送更改
git push xxx(向其发送更改的远程代码库) yyy(推送数据的本地分支的名称)

// 学会看错误提示,好像push之前要先pull,然后根据提示要准许版本历史合并
$ git pull origin master --allow-unrelated-histories

// forking  GitHub 向用户提供的直接在GitHub上copy 备份的方式,保留指向原作者的链接

git clone xxx (https://github.com/wuzhilaona/recipes.git)

// 给予合作者权限--> settings -->collaborators -->设置用户名提交

// 更新origin远程代码库的所有分支的本地副本
git fetch origin 
// 查看本地master和远程copy下来的origin/master的区别
git diff origin/master master

git pull ===  git fetch + fit merge

呐,其实还有最最最重要的拉取请求,在GitHub中十分的重要的。结合前面的知识对GitHub的操作。

课后思考题:

How did viewing a diff between two versions of a file help you see the bug that
was introduced?
查看文件的两个版本之间的差异如何帮助你了解引入的错误?

How could having easy access to the entire history of a file make you a more
efficient programmer in the long term?
从长远来看,能轻松访问文件的整个历史记录将如何提高编程者的效率?

What do you think are the pros and cons of manually choosing when to create a
commit, like you do in Git, vs having versions automatically saved, like Google
docs does?
你认为,手动选择何时创建提交(像在 Git 中做的那样)与自动保存版本(如 Google Docs 所做的那样)各有何优缺点?

Why do you think some version control systems, like Git, allow saving multiple
files in one commit, while others, like Google Docs, treat each file separately?
何你认为一些版本控制系统(例如 Git)允许在一次提交中保存多个文件,而其他系统(例如 Google Docs)单独对待每个文件?

How can you use the commands git log and git diff to view the history of files?
如何使用命令 git log 和 git diff 来查看文件的历史记录?

How might using version control make you more confident to make changes that
could break something?
使用版本控制,如何让你更有信心进行有可能会造成破坏的更改?

Now that you have your workspace set up, what do you want to try using Git for?
现在你已设置了工作空间,你想尝试使用 Git 来做些什么?
What happens when you initialize a repository? Why do you need to do it?
初始化版本库时会发生什么情况?为什么你需要这样做?

How is the staging area different from the working directory and the repository?
What value do you think it offers?
暂存区与工作目录和版本库有何不同?你认为它具有什么价值?

How can you use the staging area to make sure you have one commit per logical
change?
如何使用暂存区确保为每项逻辑更改进行一次提交?

What are some situations when branches would be helpful in keeping your history
organized? How would branches help?
在哪些情况下,分支可以帮助你有序地组织历史记录?分支将如何提供帮助?

How do the diagrams help you visualize the branch structure?
图表如何帮助你直观显示分支结构?

What is the result of merging two branches together? Why do we represent it in
the diagram the way we do?
将两个分支合并到一起有何结果?为什么我们在图表中表示它的方式是那样的?

What are the pros and cons of Git's automatic merging vs. always doing merges
manually?
Git 的自动合并与始终手动进行合并各有何优缺点?
When would you want to use a remote repository rather than keeping all your work
local?
何时你会想使用远程版本库,而不是将所有工作保存在本地?

Why might you want to always pull changes manually rather than having Git
automatically stay up-to-date with your remote repository?
为何你希望始终手动地拉取更改,而不是让 Git 自动与你的远程版本库保持同步?

Describe the differences between forks, clones, and branches.  When would you
use one instead of another?
说明Fork、克隆和分支之间的不同。何时使用某种功能而不是另一种?

What is the benefit of having a copy of the last known state of the remote
stored locally?
拥有远程分支的上次已知状态的副本(存储在本地)有何好处?

How would you collaborate without using Git or GitHub?  What would be easier,
and what would be harder?
如何在不使用 Git 或 GitHub 的情况下开展协同?哪种做法更容易?哪种做法更困难?

When would you want to make changes in a separate branch rather than directly in
master?  What benefits does each approach have?
何时你会想在独立的分支中而不是直接在 master 中进行更改?两种方法各有何好处?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值