Use GitHub
Concept Map
If you have the project to share then don't add README file.
To see all the current remotes %git remote
v stands for verbose and means that git remote will output more information
Add the repository on GitHub as a remote %git remote add remote_name URL
(If you only have one remote, it's standard to name it origin)
Send changes to the remote %git push remote_name local_branch_name
you can see know your branch have the remote branch
Get remote the project's changes to the local project %git pull remote_name local_branch_name
Copy other's project on GitHub use Fork
Update the local copy of the remote %git fetch remote_name
merge the remote master and local master %git merge local_branch remote_branch
open the file and fix it
add and commit
Update the local copy of the remote and merge with local master
%git pull origin local_branch
(git pull origin master = git fetch origin + git merge master origin/master)
當使用pull以後%git branch -a 才會出現remotes/origin/master資料夾
Use Pull requests merge the branch on GitHub
在發生conflict後merge完成不用add直接commit
對fork整體實作的流程
參考資料:
https://classroom.udacity.com/courses/ud775/lessons/3105028581/concepts/30736788930923
If you have the project to share then don't add README file.
![]() |
| If you want to create a new project then add README file and you can clone it. |
To see all the current remotes %git remote
![]() |
| If don't have any remotes yet then the output will be empty. |
v stands for verbose and means that git remote will output more information
Add the repository on GitHub as a remote %git remote add remote_name URL
(If you only have one remote, it's standard to name it origin)
Send changes to the remote %git push remote_name local_branch_name
![]() |
| The branch was pushed on GitHub |
Git push takes two arguments.The remote I want to send changes to and the name of the local branch that I'd like to push.
Get remote the project's changes to the local project %git pull remote_name local_branch_name
Copy other's project on GitHub use Fork
![]() |
| click Fork Button |
注意:可以直接更改你的Fork中的 master 分支,但是,在协同构建公共版本库时,标准的做法是在Fork内的非 master 分支中进行更改。这样一来,可以轻松让你的 master 分支与原始版本库的 master 保持同步,并在准备好时将 master 中的更改合并到分支中。
Windows 用户请注意:随着故事的发展,它已经超出了 Windows 的路径长度限制。如果你在克隆时遇到错误,可以通过修改配置设置来解决它。请在 git bash 中运行此命令:
git config --system core.longpaths true。Update the local copy of the remote %git fetch remote_name
merge the remote master and local master %git merge local_branch remote_branch
![]() |
| diff between local_branch and remote_branch |
![]() |
| merge has some conflict |
add and commit
Update the local copy of the remote and merge with local master
%git pull origin local_branch
(git pull origin master = git fetch origin + git merge master origin/master)
當使用pull以後%git branch -a 才會出現remotes/origin/master資料夾
Use Pull requests merge the branch on GitHub
![]() |
| can use edit to change where you want to merge |
在發生conflict後merge完成不用add直接commit
對fork整體實作的流程
參考資料:
https://classroom.udacity.com/courses/ud775/lessons/3105028581/concepts/30736788930923
Git merge
fast-forward merges
Only criteria for whether something would be a fast-forward merge is if the branch you are merging into is an ancestor of the branch that you're merging from.
合并冲突
如果收到类似以下所示的消息:
Auto-merging game.js CONFLICT (content): Merge conflict in game.js Automatic merge failed; fix conflicts and then commit the result.
这表示在你开始合并时,文件的状态不同于 Caroline 的文件状态。要修复此问题,请完成以下步骤:
- 运行
git merge --abort,将文件恢复到你开始合并之前的状态 - 仔细检查文件的状态。如果在检出 master 分支时运行
git log,则应看到 Caroline 的“Add color”提交是第二新的提交,而最新的提交应为你修复 bullet 错误的提交。如果使用git diff将你的提交与 Caroline 的提交进行对比,你的提交应在第 424 行引入this.delayBeforeBullet = 10;这行代码。应仅使用空格(无制表符)使该行的缩进程度与其下面一行相同,而且该行之后应无空格。 - 在文件处于正确的状态后,利用你所做的更改新建一个提交。
- 重新尝试合并。
合并冲突(Windows 与 Unix 系统之间的换行符)
背景:按下键盘上的“Enter”键时,实际上是告诉计算机在文本文件中插入一个不可见的字符,以便指示计算机应新起一行。Unix 系统会添加一个名为“换行”符的字符(或者 LF 或 \),而 Windows 系统会添加两个字符,即“回车”和“换行”(或者 CRLF 或 \r\n)。
Caroline 的文件包含 LF,因为她的文件是在使用 LF 的 Mac OSX 上编辑的。如果某 Windows 用户要编辑 Caroline 的文件,Windows 文本编辑器可能会将所有 LF 均转换为 CRLF,以便该用户能够编辑文件。在该 Windows 用户将她的文件与 Caroline 的文件合并时,不同的 LF 和 CRLF 字符将会造成合并冲突。
要修复此问题,Windows 用户应将 autocrlf 全局属性设置为 true:
git config --global core.autocrlf true。有关更多信息,请访问以下网址:https://help.github.com/articles/dealing-with-line-endings/#platform-all将提交与所在分支进行对比
Caroline 提到的将提交与所在分支进行对比的命令是
git show commit_id當出現conflict時
<<<<
|||||| merge common ancestors
//The middle section is the original version that both branches modified
====
//The bottom section, marked master is the code that's in master right now.>>>>>master
參考資料來源
https://classroom.udacity.com/courses/ud775/lessons/2969618657/concepts/29892386280923
Subscribe to:
Posts (Atom)






















