Just relax, take it easy..

0%

Notes of Atlassian git tutorial

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 branch
git 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 " to remove the specified file from the staging area, but leave the working directory unchanged.)

  • "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
2
3
4
5
6
7
8
9
# Edit some existing files
# Add some new files
# Realise you have no idea what you're doing

# Undo changes in tracked files
git reset --hard

# Remove untracked files
git clean -df

###Rewriting history###
git commit --amend:

1
2
3
4
5
6
7
# Edit hello.py and main.py
git add hello.py
git commit

# Realise you forgot to add the changes from main.py
git add main.py
git commit --amend --no-edit

###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
2
3
[branch "master"]
remote = origin
merge = refs/heads/master

merge conflict

Automatic merge failed; fix conflicts and then commit the result.
Try: git mergetool