Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X

Git Cheat Sheet - Part 2

Here is the continuation of my first post on Git command cheat sheet, here is the part one of the post. Git is open source distributed version control system that facilitates GitHub activities on your laptop or desktop. This cheat sheet summaries commonly used Git command line instructions for quick reference.

Refactor Filenames

Relocate and remove versioned files

$ git rm [file]

Deletes the file from the working directory and stages the deletion

$ git rm --cached [file]

Removes the file from version control but preserves the file locally

$ git mv [file-original] [file-renamed]

Changes the file name and prepares it for commit

Suppress Tracking
Exclude temporary files paths

*.log
build/
temp-*

A text file named .gitignore suppresses accidental versioning of files and paths matching the specified patterns

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

Lists all ignored files in this project

Save Fragments
Shelve and restore incomplete changes

$ git stash

Temporarily stores all modified tracked files

$ git stash pop

Restores the most recently stashed files

$ git stash list

List all stashed changesets

$ git stash drop

Discards the most recently stashed changeset

Review History
Browse and inspect the evolution of project files

$ git log

Lists version history for the current branch

$ git log --follow [file]

Lists version history for a file, including renames

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

Shows content differences between twi branches

$ git show [commit]

Ouputs metadata and content changes of the specified commit

Redo Commits
Erase mistakes and craft replace history

$ git reset [commit]

Undoes all commits after [commit], preserving changes locally

$ git reset --hard [commit]

Discards all history and changes back to the specified commit


Synchronize Changes
Register a repository bookmark and exchange version history

$ git fecth [bookmark]

Downloads all history from the repository bookmark

$ git merge [bookmark]/[branch]

Combines bookmark's branch into current local branch

$ git push [alias] [branch]

Uploads all local branch commits to Github

$ git pull

Downloads bookmark history and incorporates changes

The System Utility

$ git fsck

Validate system files

Files showing as modified directly after git clone

$ git config core.fileMode false

I ran into a funny issue. I cloned a repository, then cd into the repo, did some chmod and git-status shows several files as changed. Note: I haven't opened the repo in any editor or anything. I was so confused, above command resolved the issue.

 

Drop a comment...

 


comments powered by Disqus