Here is a cheat sheet for git.
1. Create
git init # create a local repository
git clone <url> # clone a repository from url
2. Commit
git commit -m "commit message"
3. Browse
git log # history of change
git status # files changed in working directory
git diff # diff between working directory and the index
git diff HEAD # diff between working directory and the most recent commit
git diff --cached # diff between the index and the most recent commit
git show <object> # show object
gitk # git repository (GUI) browser
4. Stage
git add <file> # add file to the index
git reset HEAD <file> # unstage the staged file
5. Undo
git commit -a --amend # fix the last commit
git reset --hard <commit> # discard any changes and reset to the commit
git revert HEAD # revert the last commit
git revert <commit> # revert the specific commit
git checkout -- <file> # unmodify the modified file
6. Branch
git branch <new_branch> # create a branch named new_branch based on HEAD
git branch -d <old_branch> # delete the branch named old_branch
git checkout <branch> # switch to the branch
git checkout -b <branch> # create a new branch then switch to it
git merge <branch> # merge the specified branch into HEAD
7. Update
git fetch # download latest changes from origin
git pull # fetch from and integrate (merge) with origin
8. Publish
git push # update origin
No comments:
Post a Comment