Although we have powerful tools such as sourcetree,
learning the details of git is still very necessary.
I found a fantastic tutorial:https://www.atlassian.com/git/tutorials, this is my learning notes.
###git log vs git status###git log
: showing all the comments in this branchgit status
: showing the overview of this branch
###Show commits in graph###
draw a graph of all comments:
1 | git log --graph --decorate --oneline |
###git diff###
- Using "git diff" to compare two commits.
###Undoing Changes###
- "git add
..." to update what will be committed(stage changes)
"git reset
- "git revert
" to generate a new commit that undoes all of the changes introduced in , then apply it to the current branch.
"Whereas reverting is designed to safely undo a public commit, git reset is designed to undo local changes."
"The git reset --hard
and git clean -f
commands are your best friends after you’ve made some embarrassing developments in your local repository and want to burn the evidence."
Example:
1 | # Edit some existing files |
###Rewriting history###
git commit --amend:
1 | # Edit hello.py and main.py |
###Difference of git fetch and git pull###git pull
= git fetch
followed by a git merge
(remote branch).
Still a little confused.
这篇文章解释的很清楚:http://www.ruanyifeng.com/blog/2014/06/git_remote.html?20160711102657
'fetch' is updating the remote branch info, then local branch merge to remote branch !!
###git set defaul remote to push ###
Edit your .git/config
1 | [branch "master"] |
merge conflict
Automatic merge failed; fix conflicts and then commit the result.Try: git mergetool