You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Provide details about Repo & Git commands

Git Command Referrence

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

checkout

To switch to another branch in your local work environment.

$ git checkout BRANCH_NAME

add

To stage changes[file modifications and deletions].Accepts arguments for files or directories within the project directory. 

$ git add

Options:

$ git add [options]

  • -n  , --dry-run :Don’t actually add the file(s), just show if they exist and/or will be ignored.
  • -v , --verbose :Be verbose.
  • -f , --force      :Allow adding otherwise ignored files.
  • -i , --interactive : Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree.
  • -p , --patch   : Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.
  • -e , --edit  :Open the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and apply the patch to the index.
  • -u ,–update :Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.

Examples:

Adds content from all *.txt files under Documentation directory and its subdirectories.

$ git add Documentation/\*.txt


commit

Consists of a snapshot of the directory structure and file contents for the entire project.Record changes to the repository.

$ git commit

Options:

  • -a , --all : Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
  • --p , --patch : Use the interactive patch selection interface to chose which changes to commit.
  • -C <commit> ,  --reuse-message=<commit> : Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
  • -c <commit> , --reedit-message=<commit> : Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.
  • --squash=<commit> : Construct a commit message for use with rebase --autosquash
  • --branch : Show the branch and tracking info even in short-format.
  • -F <file> , --file=<file> : Take the commit message from the given file. Use - to read the message from the standard input.

branch

To view a list of existing branches

$ git branch

Creates a new topic branch

$ git branch [branch]

merge

Merges [branch] into current branch.

$ git merge [branch]

diff

Shows diff of the unstaged changes.

$ git diff

Shows diff of the staged changes.

$ git diff --cached

log

Shows the history of the current branch.

$ git log

Shows the commits that aren't pushed.

$ git log m/[codeline]..

rebase

Reapply commits on top of another base tip.

$ git rebase [options]

Options :

  • -i , --interactive : Make a list of the commits which are about to be rebased. Let the user edit that list before rebasing.
  • --continue  : Restart the rebasing process after having resolved a merge conflict.
  • --abort :Abort the rebase operation and reset HEAD to the original branch.
  • --quit : Abort the rebase operation but HEAD is not reset back to the original branch. The index and working tree are also left unchanged as a result.
  • --onto <newbase> : Starting point at which to create the new commits. If the --onto option is not specified, the starting point is <upstream>. May be any valid commit, and not just an existing branch name.
  • --skip  : Restart the rebasing process by skipping the current patch.
  • --edit-todo : Edit the todo list during an interactive rebase.
  • -m ,–merge  :Use merging strategies to rebase. When the recursive (default) merge strategy is used, this allows rebase to be aware of renames on the upstream side.
  • --show-current-patch  :Show the current patch in an interactive rebase or when rebase is stopped because of conflicts. This is the equivalent of git show REBASE_HEAD.

stash

Stash the changes in a dirty working directory away.when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

Options :

  • list [<options>] : List the stash entries that you currently have. Eachstash entryis listed with its name (e.g.stash@{0}is the latest entry,stash@{1}is the one before, etc.),
  • show [<options>] [<stash>] :  Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created.
  • drop [-q|--quiet] [<stash>]  :  Remove a single stash entry from the list of stash entries. When no<stash>is given, it removes the latest one. i.e.stash@{0}, otherwise<stash>must be a valid stash log reference of the formstash@{<revision>}.
  • branch <branchname> [<stash>] : Creates and checks out a new branch named<branchname>starting from the commit at which the<stash>was originally created, applies the changes recorded in<stash>to the new working tree and index. If that succeeds, and<stash>is a reference of the formstash@{<revision>}, it then drops the<stash>. When no<stash>is given, applies the latest one.
  • clear : Removes all the stash entries
  • create : Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace.
  • store  :Store a given stash created via git stash create (which is a dangling merge commit) in the stash ref, updating the stash reflog. 
  • No labels