Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

  • git checkout <branch name>–  Switch branches or restore working tree files

 

  • git checkout -b <branch-name> - creates a new branch from current branch
  • git status – checks changes made to files
  • git add <file name> - adds only specified file to staging
  • git add * -  adds all files to staging
  • git commit –m “message” -  Records changes to the repository (Note: To link GIT commit and JIRA issue add the issue number is the commit message)
  • git push – Updates remote refs along with associated objects
  • git pull –  Fetches from and integrate with another repository or a local branch
  • git checkout – delete all the changes except untracked changes
  • git merge – merge two branches 
  • git rm - Remove files from the index, or from the working tree and the index
  • git checkout <commit #> - Temporarily switch to a different commit (This will detach your HEAD, that is, leave you with no branch checked out
  • Undo published commits with new commits
  • Hard delete unpublished commits: This will destroy any local modifications. Don't do it if you have uncommitted work you want to keep.
    •  If there's work to keep: git revert a b c: # This will create three separate revert commits
    •  git revert HEAD~2..HEAD: # It also takes ranges. This will revert the last two commits
    •  git revert a867b4af..0766c053: Similarly, you can revert a range of commits using commit hashes
    • git revert -m 1 <merge_commit_sha>:# Reverting a merge commit
    •  git checkout 0d1d7fc32:  To get just one, you could use `rebase -i` to squash them afterwards Or, you could do it manually (be sure to do this at top level of the repo) get your index and work tree into the desired state, without changing HEAD:
    •  git commit: # Be sure and write a good message describing what you just did
    •  git reset --hard 0d1d7fc32
    •  git stash
    •  git reset --hard 0d1d7fc32
    •  git stash pop: This saves the modifications, then reapplies that patch after resetting. You could get merge conflicts, if you've modified things which were changed since the commit you reset to.