GIT CHEAT SHEET

GIT is the open source distributed version control system that facilitates GitHub activities on your laptop or desktop. This cheat sheet summarizes commonly used Git command line instructions for quick reference.

INSTALL GIT

FOR ubuntu
sudo apt-get install git

COMMAND

CONFIGURED TOOLING

  1. Sets the name your want ro attached to your commit transactions
    git config --global user.name "[name]"
  2. Sets the email you want attached to your commit transactions
    git config --global user.email "[email address]"
  3. Enables helpful colorization of command line output
    git config --global color.ui auto

CREATE REPOSITORIES

  1. Creates a new local repository with the specified name
    git init [project-name] or cd [project-name] && git init
  2. Downloads a project and its entire version history
    git clone [url]

MAKE CHANGES

  1. Lists all new or modified files to be commited
    git status
  2. Show file differences not yet staged
    git diff
  3. Snapshots the file in preparation for versioning
    git add [file]
  4. Show file differences between staging and the last file version
    git diff --staged
  5. Unstages the file, but preserve its contents
    git reset [file]
  6. Records file snapshots permanently in version history
    git commit -m "[descriptive message]"

GROUP CHANGES

  1. Lists all local branches in the current repository
    git branch
  2. Create a new branch
    git branch [branch-name]
  3. Switches to the specified branch and updates the working directory
    git checkout [branch-name]
  4. Combines the specified branch's history into the current branch
    git merge [branch]
  5. Deletes the specified branch
    git branch -d [branch-name]

REFACTOR FILENAMES

  1. Deletes the file from the working directory and stages the deletion
    gti rm [file]
  2. Removes the tile from version control but preserves the file locally
    git rm --cached [file]
  3. Changes the file name and prepares it for commit
    git mv [file-original] [file-renamed]

SUPPRESS TRACKING

  1. Lists all ignored files in this project
    git ls-files --other --ignored --exclude-standard

SAVE FRAGMENTS

  1. Temporaily stores all modified tracked files
    git stash
  2. Restores the most recently stashed files
    git stash pop
  3. Lists all stashed changesets
    git stash list
  4. Discards the most recently stashed changeset
    git stash drop

REVIEW HISTORY

  1. Lists version history for the current branch
    git log
  2. Lists verson history for a file, including renames
    git log --follow [file]
  3. Shows content differences between two branches
    git diff [first-branch]...[second-branch]
  4. Outputs metadata and content changes of the specified commit
    git show [commit]

REDO COMMIT

  1. Undoes all commits after [commit], preserving changes locally
    git reset [commit]
  2. Discards all history changes back to the specified commit
    git reset --hard [commit]

SYNCHRONIZE CHANGES

  1. Downloads all history from the repository bookmark
    git fetch [bookmark]
  2. Combines bookmark's branch into current local branch
    git merge [bookmark]/[branch]
  3. Uploads all local branch commits to GitHub
    git push [alias] [branch]
  4. Downloads bookmark history and incorporates changes
    git pull

你可能感兴趣的:(GIT CHEAT SHEET)