Last active
March 15, 2018 00:34
-
-
Save venkatmarepalli/b7770a5675d9e1b7f6f3674465da4f97 to your computer and use it in GitHub Desktop.
Common Useful GIT Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Nice Tutorial | |
| #http://rogerdudler.github.io/git-guide/ | |
| #View committed files those are not pushed yet | |
| git diff --stat origin/master | |
| #View list of files that are to be pushed | |
| git diff --stat --cached origin/master | |
| #Replace local changed files with gits version | |
| git checkout -- <filename> | |
| #Add file or folder to git | |
| git add <file> | |
| git add <folder>/* | |
| git status | |
| git commit -m "fixed redirection issue" | |
| git status | |
| git push origin master:refs/publish/master | |
| #Check Current working branch | |
| #This does not work if you are in a 'detached HEAD' state | |
| git rev-parse --abbrev-ref HEAD | |
| #Check first line after running this | |
| git status | |
| #Switch to another Branch | |
| git checkout branch_name | |
| #Remove file from GIT | |
| git rm --cached filename | |
| #To Change previous commit message and commit (Add commit message in text editor which is opened after issuing this command) | |
| git commit --amend | |
| #Fetch latest code from the source | |
| #No conflicts with new-online version | |
| git fetch origin | |
| git status | |
| #Your branch is behind 'origin/master' by x commits, and can be fast-forwarded. | |
| #Get the latest version | |
| git pull | |
| #This command below is to resolve the issue of Your branch is ahead of X commits message even after we executed git pull command | |
| #If you want to sync origin/master mark to current master HEAD just type | |
| git update-ref refs/remotes/origin/master cac0cab538b970a37ea1e769cbbde608743bc96d | |
| #where instead of this hash put your hash of the head from: | |
| git log -1 | |
| #TO check the currect HEAD reference | |
| git show-ref master | |
| #refs/heads/master --> local git pointing Hash | |
| #refs/remotes/origin/master --> remote git pointing Hash | |
| #More here https://git-scm.com/docs/git-show-ref | |
| #This is to reset the commit. For example you committed few changes and removed those files and did git commit --amend to update the commit to remove the files. | |
| #You an enter this command to reset your HEAD to point to the main commit when you pulled your code | |
| git reset HEAD^ | |
| #Checkout to a commit version and into a new branch | |
| git checkout <commit> -b branch_name | |
| #What’s happening here? Git will rewind (undo) all of your local commits, pull down the remote commits then replay your local commits | |
| #on top of the newly pulled remote commits. If any conflicts arise that git can’t handle you’ll be given the opportunity to manually | |
| #merge the commits then simply run git rebase --continue to carry on replaying your local commits. | |
| #Ref: http://kernowsoul.com/blog/2012/06/20/4-ways-to-avoid-merge-commits-in-git/ | |
| git pull --rebase | |
| #List all tags | |
| git tag | |
| # --all will fetch all the remotes. | |
| # --tags will fetch all tags as well | |
| git fetch --all --tags --prune | |
| #To checkout a tag, run above command before running this. | |
| git checkout tags/<tag_name> -b <branch_name> | |
| #To remove a file from the already committed changeset | |
| #Ref: https://stackoverflow.com/questions/12481639/remove-files-from-git-commit | |
| git reset HEAD^ -- path/to/file | |
| git commit --amend --no-edit | |
| #Go back in History in GIT | |
| #REF: https://blog.github.com/2015-06-08-how-to-undo-almost-anything-with-git/ | |
| git reflog | |
| #If you want to restore the project’s history as it was at that moment in time use | |
| git reset --hard <SHA> | |
| #If you want to recreate one or more files in your working directory as they were at that moment in time, without altering history use | |
| git checkout <SHA> -- <filename> | |
| #If you want to replay exactly one of those commits into your repository use | |
| git cherry-pick <SHA> | |
| git log --pretty=oneline | |
| git log --pretty=oneline --abbrev-commit | |
| #-1 means list one log | |
| git log --pretty=oneline --abbrev-commit --reverse -1 | |
| # TO display date | |
| git log --pretty=format:"%h %Cblue%ad%Creset %ae %Cgreen%s%Creset" --reverse -10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment