Featured Post

git commands list


# Create a repo on github then call the below
#git remote add origin  https://github.com/srampv/CounterWebApp.git
#git push -u origin master

##############################
#                Common cmds             #
##############################
git add .                                                                # Stage all new & mod files from .
git add -u                                                             # Stage everything new & deleted files/dirs
git add -p                                                             # Stage with confirmation of displayed changes
giit commit -m "My log note"
git push
git log
git log myfile.rb                                                 # See commit history on myfile.rb
git log -p myfile.rb                           # See commit code changes on myfile.rb
git status
git mv oldname newname                           # Renaming files

##############################
#                Diff/Compare                  #
##############################
git diff                                                                   # Unstaged vs Staged changes
git diff --staged                                                 # Staged vs HEAD changes
git diff HEAD                                                       # UnStaged vs HEAD changes
git diff v1.0 v1.1                                                # Dif between 2 versions
git diff v1.0 v1.1 --stat                    # Dif with formatting

git show xxxcommit                                                              # Show what’s in the commit
git show --pretty="format:" --name-only xxxcommit # Show file committed only


# To stop Unix file permission mode comparison “old mode 100644 vs new mode 100755”
git config core.filemode false    

##############################
#                Roll back                         #
##############################
git reset                                                    # To unstage previous add
git reset HEAD                       # To unstage
git checkout HEAD --                          # To discard changes in working directory)
git reset --hard HEAD                                     # To rollback everything to tip
git reset --hard 6f583101                               # To rollback commit to 6f583101
git reset --                                               # To unstage previous file delete
git checkout --                                       # To bring back previously deleted file from remote
git checkout 0d1d7fc32                  # Detach from head and leave you @ no branch
git reset --hard       # Roll back to commgit it version and lose all history after that version
git push -f                                           # Force push the roll back changes to remote


##############################
#                Stash                              #
##############################
git stash                                                               # Move staged changes to a temp stash “branch”
git stash save "My descrip"                               # Stash with a descriptive name
git stash list                                                         # Display all stashed data
git stash apply                                                   # Apply the latest stash stored
git stash pop                                                      # Apply the latest stash stored and remove it from storage
git stash apply stash@{n}                             # Apply the stash at index n
git stash apply stash^{/My desc}               # Apply the latest stash that regex matches “My desc”
git stash branch                 # Take the stash and create an actual branch

##############################
#                Stashing                          #
##############################
git stash                                                               # Stash with a default description
git stash save "my change"                          # Stash with a description
git stash list
git stash pop                                                      # Retrieve the 1st index
git stash pop stash@{0}                                 # Retrieve the 1st index
git stash drop stash@{1}                               # Remove the 2nd stash index
git stash clear                                                     # Remove all stashes
git stash --keep-index                                    # Stash while leaving staged files
git stash show -p stash@{0}                        #  Diff of local vs stash

##############################
#                Branching                       #
##############################

git branch                                                            # Display all the branches
git branch -r                                        # Display all the remote branches
git checkout -b my_nu_branch # Create a new local branch
git push -u origin my_nu_branch             # Push nu branch onto remote

git fetch origin                                                   # Retrieve all remote branches
git checkout  my_branch                              # Go to my_branch
git checkout master                                        # Go back to the master branch

git merge my_nu_branch                             # Merge my_nu_branch back into master

git branch -d my_nu_branch                       # Delete my_nu_branch
git log --graph                                                    # Display “train tracks” of branches
git branch -d my_local_branch   # Delete local branch
git push origin --delete my_branch          # Delete remote branch

# Merging new commits from the master branch to the derived branch ie my_branch
git fetch origin develop                                # Fetch the changes from develop; saving the target branch as FETCH_HEAD
git checkout my_branch
git merge FETCH_HEAD                                # Merge FETCH_HEAD to my_branch

##############################
#                Miscellaneous                 #
##############################
git rm my_file.rb                                              # Remove a file from git repository
git reset --hard                                                  # Blow away local changes
git fetch --all                                                       # Blow away local changes
git revert HEAD                                 # Roll back to the next to last commit    
git remote                                                           # Show the remote repository
git remote -v                                                      # Show the remote repository’s url
git diff > patch.andrei                                     # create a patch file
git diff --cached > ~/patch.aug22              # create a patch file from staged files only
git apply /mydir/mychange.patch
git clone https://XXXX                   # Grabbing repository from github for the 1st time.
git log --grep 636426556
git push [origin] [mybranch1]                        # Pushing to remote

Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...