Git Notes

draft, need to orgnize

git commit

commit changes from staging area, instead of files
-a will commit changes from staging area and working dir, but that file should be tracked
–amend, amend last commit, local only, do not do amend after push

git checkout => walk around in commits and branchs

1. checkout <commit>
2. checkout <commit> <file>
3. branch
> only change working dirs

git revert

create a new commit to pretend a roll back. safe command.

git reset => delet history

1. git reset <file>  => unstaging
    clean up staging area, but leave working directory unchanged
    --hard will also reset working directory to match last commit
2. git reset <commit>
    unstaging + remove commits
    --hard will also reset working directory

do not reset to the commit after a push, use revert! reset is used locally only.
danger, reset can’t undo even via reflog!

compare them

checkout just changes the working dir
reset removes the commits
revert adds a commit to perform like a roll back
above three comman only affet tracked files.

git clean => remove untracked files

always need -f to perform
need -d to delete dirs
will not delete files listed in .gitignore

git merge

merge the to current branch, if nothing is added into current branch, git will conduct a ‘fast-forward’ merge, which just add the following current branch. If both branch have some commits, git will add a merge commit.

git pull

git pull == git fatch + git merge remote/master

git rebase => facilitates a fast-forward merge

–rebase -i => squash history

git reflog => contains the history about rollback

in case of conflict

relax, just re-edit the conflict files, and commit again~

git remote show

git push will link the local brach with remote branch, which means this branch is being tracked. (only changes will be commited. so if you just ‘git push’, git will not process untracked branch)
git push : will link with two different names.