Web

Git Cheat Sheet

걷는이 2019. 4. 25. 01:26

초기화

   git init [project-name]   // create a new local repository with the specified name

   git clone [url] // Download a project and its entire version history

 

Basic

   git add [file]   // snapshot the file in preparation for versioning, move to stage

   git reset [file] // Unstage the file, but preserve its contents

   git commit -m "[message]" // records file snapshot permanently in version history

 

   git status

   git diff

   git diff --staged

 

Sync

   git pull   // same as git fetch + git merge ; make local branch up-to-date

   git fetch [bookmark] // download all history from the repository bookmark, no change in your working copy

   git merge [bookmark]/[branch] // combine bookmark's branch into current local branch

   git push [alias] [branch]  // upload all local branch commits to Git server

 

Group changes

   git branch

   git branch [branch-name]   // Create a new branch

   git checkout [branch-name]  // Switch to the specified branch and update the working directory

   git branch -d [branch-name]   // Delete a branch

   git merge [branch]  // combine the specified branch's history into current branch

 

Save Frangments

   git stash // temporarily store all modified tracked files

   git stash pop // restore the most recently stashed files

   git stash list

   git stash drop // discard the most recently stashed files

 

Redo commit

   git reset [commit]  // undo all commits after [commit], preserving changes locally

   git reset --hard [commit]  // Discard all history and changes, back to the specified commit

 

Log

   git log  // show all histoy of current branch

   git log --follow [fiel] // list version history for a file including renames

   git diff [first-branch]...[second-branch]   

   git show [commit]  // Display metadata and content changes of the specified commit

 

Ignore files to track   

   .gitignore 

   git ls-files --other --ignored --exclude-standard

 

Refactor filenames

   git rm [file] // delete the file from the working directory and stages

   git rm --cached [file]  // Remove the file from the version control, but preserve the file locally

   git mv [file-original] [file-renamed]  // Change the file name and prepare it for commit

 

 

TIP:

   Merge conflict: 

       git pull  // maybe error(merge conflict)

       git stash

       git pull

       git stash pop