Skip to content

Latest commit

 

History

History
114 lines (90 loc) · 3.38 KB

File metadata and controls

114 lines (90 loc) · 3.38 KB

Git cheat sheet

Simple git cheat sheet, base on great udacity git course for beginners and Learn Git with Bitbucket Cloud.

Table of content

Git config

git config user.name "user_name"
git config user.email "user@email.com"
---
git config --global user.name "user_name"
git config --global user.email "user@email.com"

Git log, checking history of repo.

git status
git log

git log

git log --oneline #log all commit in one line
git log --stat #log all commit and changed files
git log -p #log all commit and show change in commit

git log --oneline --graph --all

Git commit

git add . #move all changed file from Working Directory to the Staging Index
git commit -m "Commit message show" #commit
git diff #Show changes that have been made but haven't been committed, yet.

Remember about .gitignore file :)

Git tag

git tag -a v0.1 -m "tag message" #create new tag
git tag -d v0.1 #delete tag

Git branching

git branch #show branch
git branch new-branch master #create new-branch
git checkout new-branch #switch to new-branch
git checkout -b second-branch #create and switch to second-branch
git branch -d new-branch #delete new-branch

Git merge

git merge second-branch #merge second-branch

Git undoing changes

Git undoing changes another reference.

Changing The Last Commit

git commit --amend

# Edit hello.py and main.py git add hello.py git commit
# Realize you forgot to add the changes from main.py git add main.py
git commit --amend --no-edit

Git revert

git revert <SHA-of-commit-to-revert>

Git reset

Reverting creates a new commit that reverts or undo a previous commit. Resetting, on the other hand, erases commits!

git reset <reference-to-commit>

three flags:

  • --mixed default (unstages committed changes)
  • --soft (moves committed changes to the staging index)
  • --hard (erase commits)

You've got to be careful with Git's resetting capabilities. This is one of the few commands that lets you erase commits from the repository. If a commit is no longer in the repository, then its content is gone.

To alleviate the stress a bit, Git does keep track of everything for about 30 days before it completely erases anything. To access this content, you'll need to use the git reflog command.

Git collaborating