這是兩年前 GitHub 來成大教育課程的筆記
最近在整理 git 的筆記才翻出來
這篇的內容可能比較雜亂，之後還會再整理進另一篇 git 的筆記
Introduction to Git Hub (Company)
There are around 2600 staffs in GitHub and 40% of them live in San Fransisco.
Among them, there is one Taiwanese.
Wrote by Linus Torvalds.
Why version control?
- Historical propose
git init "path"
.git is just a folder with normal file
There is no daemon or background progress
Everything is operated in file
rm -rf .git XD
git stauts touch README.mdd
There are three main stages
git add README.md
When we're ready
git commit -m "add a blank commit"
After README.md is modified
git add README.md git status
Now this file is in staging area
So, how to go back to history?
git reset README.md
Take a look at our history
Go back to history
git checkout "SHA1"
git checkout master
Everything comes back
master is the default branch name of git. It is a default word but not reserved.
git checkout -b "branch_name" create a branch and checkout to it
git diff: View the difference between working and staging
git diff --staged: Difference between staging and repo
git diff "SHA1": Difference between current version and SHA1
git diff master~1: difference between current and the one before master
git diff master^ → master~1
git diff master^^ → master~2
git diff a b: Show the change from a to b
In git, branch is not copy. It's like bookmark
git branch -d "name" just delete the pointer but not the entry.
HEAD: the pointer points to current entry
If you go back to a entry not in certain branch, a detach error might occur.
For example, checkout to a commit that is parent of more than one branch and then append a new commit to it.
In such case, this new appended commit might not be able to be referenced.
The solution to this problem is to create a new branch for it.
git log --decorate: Show also branch info
git log --all: Show all branch
git log --graph: Show graph
The difference between log and show
git log: Only the first line
git show: All the message, not only the first line
origin is a short hand name of that remote url. In other word, your repo.
git push -u origin master
- upload master to origin
8 -u tell git the default url to push for that branch(master) is origin, it would also make
-uand after that you can just use
git push --all: push all branch
git pull --prune
difference between fetch and pull
git fetch : go to remote and copy it
git pull → fetch + merge
pull request on GitHub
@person-name → notification
Have a conversation with the whole team
Write "fix #2 ...." in git commit → special meaning → specify the bug in issue on GitHub
Wiki → documentation
How to write a good git commit
- Separate each commit
- Let the commit tell a story
- One line 80 character
- Use present tense instead of past tense
- Don't repeat what can be found in
- If more detail is to be written, left the second line to be blank.
- Write more detail about why this change happened after the third line.
git config --global -e: Edit your .gitconfig file.
Not include binary files and executable
Don't version control these kinds of files.
Also, large files are not recommended to add to git.
If it's needed, try
git revert "SHA1" → save another entry of undo
If you commit the password →
git rebase can change commit, but it is not that recommended.
git submodule create a sub-module