git

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

git log <file>

Only display commits that include the specified file. This is an easy way to see the history of a particular file.

git config --global --edit

Open the global configuration file in a text editor for manual editing.

git clean -n

Perform a "dry run" of git clean. This will show you which files are going to be removed without actually doing it.

git push <remote> --all

Push all of your local branches to the specified remote.

git push <remote> <branch>

Push the specified branch to <remote>, along with all of the necessary commits and internal objects. This creates a local branch in the destination repository. To prevent you from overwriting commits, Git won't let you push when it results in a non-fast-forward merge in the destination repository.

git rebase -i <base>

Rebase the current branch onto <base>, using an interactive rebasing session.

git rebase <base>

Rebase the current branch onto <base>, which can be any kind of commit reference (an ID, a branch name, a tag, or a relative reference to HEAD).

git rm <file>

Remove <file> from the index, staging it for deletion. Also remove it from working area, unless --cached is given.

git remote rm <name>

Remove the connection to the remote repository called <name>.

git stash pop

Remove the top stash from the stack, and apply it into the working directory and index.

git clean -df

Remove untracked files and untracked directories from the current directory (by force).

git clean -xf

Remove untracked files from the current directory as well as any files that Git usually ignores.

git clean -f

Remove untracked files from the current directory. The -f (force) flag is required unless the clean.requireForce configuration option is set to false (it's true by default). This will not remove ignored folders or files.

git clean -f <path>

Remove untracked files, but limit the operation to the specified path.

git clean

Removes untracked files from your working directory. This could also be done by seeing which files are untracked with git status, and removing them manually. Like an ordinary rm command, git clean is not undoable, so make sure you really want to delete the untracked files before you run it. The git clean command is often executed after git reset --hard. Remember that resetting only affects tracked files, so a separate command is required for cleaning up untracked ones. Combined, these two commands let you return the working directory to the exact state of a particular commit.

git remote rename <old-name> <new-name>

Rename a remote connection from <old-name> to <new-name>.

git branch -m <branch>

Rename the current branch to <branch>.

git reset [with no args]

Reset staging area to match the repo at HEAD (but this changes with <mode>, <path>, and/or <commit>).

git reset --hard

Reset the staging area and the working directory to match the most recent commit (because the default is HEAD), thus overwriting all changes in the working directory.

git checkout -b <branch>

Create and check out on the specified branch.

git merge <branch>

Merge the branch called <branch> into the current branch

git merge <fetched-remote-name>

Merge all the files downloaded from the specified repository into the current branch

git blame <filename>

Annotate each line in the given file with information about the revision which last modified the line.

git blame -L <start>,<end> <filename>

Annotate specified lines in the given file with information about the revision which last modified each line.

git stash apply <number-in-list>

Apply the changes from the given stash number in the stash stack.

git log --graph --decorate --oneline

A few useful options to consider. The --graph flag that will draw a text based graph of the commits on the left hand side of the commit messages. --decorate adds the names of branches or tags of the commits that are shown. --oneline shows the commit information on a single line making it easier to browse through commits at-a-glance.

git add

Adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. git add doesn't affect the repository directly—changes are not actually recorded until you run git commit.

git log --merge

After a failed merge, show refs that may be responsible: i.e., refs that touch conflicted files and that aren't reachable from all the refs that were merged. (Not to be confused with --merges!)

git log --stat

Along with the ordinary git log information, include which files were altered and the relative number of lines that were added or deleted from each of them.

git add -p

Begin an interactive staging session that lets you choose portions of a file to add to the next commit. This will present you with a chunk of changes and prompt you for a command. Use y to stage the chunk, n to ignore the chunk, s to split it into smaller chunks, e to manually edit the chunk, and q to exit.

git checkout HEAD <file>

Change <file> in working tree and in index to match the HEAD version of <file> in the repo.

git checkout <commit> <file>

Check out a previous version of a file. This turns the <file> that resides in the working directory into an exact copy of the one from <commit> and adds it to the staging area.

git checkout <branch>

Check out the specified branch, which should have already been created with git branch. This makes <existing-branch> the current branch, and updates the working directory to match.

git commit --amend

Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot. Running this when there is nothing staged lets you edit the previous commit's message without altering its snapshot. A convenient way to fix up the most recent commit. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot. It can also be used to simply edit the previous commit message without changing its snapshot.

git diff

Command to compare the files in staging area with the files in working directory

git diff <first> <second>

Command to compare two specified branches or commits

git push

Command to send all the commits from local repository to remote repository

git push <remote> --tags

Command to send all the tags to remote repository

git checkout master

Command to switch from current branch in to the branch called "master"

git commit

Commits the staged snapshot to the project history. Committed snapshots can be thought of as "safe" versions of a project—Git will never change them unless you explicity ask it to. While they share the same name, this command is nothing like svn commit. Snapshots are committed to the local repository, and this requires absolutely no interaction with other Git repositories.

git diff <first-branch> <second-branch>

Compare (the tips of) two specified branches.

git config

Configures the Git installation (or an individual repository) from the command line. This command can define everything from user info to preferences to the behaviour of a repository.

git clone

Copies an existing Git repository. This is sort of like svn checkout, except the "working copy" is a full-fledged Git repository—it has its own history, manages its own files, and is an isolated environment from the original repository. As a convenience, cloning automatically creates a remote connection called origin pointing back to the original repository. This makes it very easy to interact with a central repository.

git branch <branch>

Create a new branch called <branch> but does not check out the new branch

git remote add <name> <url>

Create a new connection to a remote repository. After adding a remote, you'll be able to use <name> as a convenient shortcut for <url> in other Git commands.

git config --global alias.<alias-name> <git-command>

Create a shortcut for a Git command.

git tag <name> <commit>

Create a tag (named reference to a commit). If no commit is given, defaults to HEAD. Use -a to create an annotated tag; otherwise a lightweight tag.

git init <directory>

Create an empty Git repository in the specified directory. Running this command will create a new folder called <directory> containing nothing but the .git subdirectory.

git config --global user.email <email>

Define the author email to be used for all commits by the current user.

git config --global user.name <name>

Define the author name to be used for all commits by the current user.

git config user.name <name>

Define the author name to be used for all commits in the current repository. Typically, you'll want to use the --global flag to set configuration options for the current user.

git config --system core.editor <editor>

Define the text editor used by commands like git commit for all users on the current machine. The <editor> argument should be the command that launches the desired editor (e.g., vi).

git branch -d <branch>

Delete the specified branch.

git log

Display a list of commits (snapshots)

git stash list

Display a list of stashes (name and description).

git help <command>

Display help information about <command>.

git log -p

Display the patch (lines added and removed) of each commit.

git status

Displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.

git fetch <remote>

Download refs (branches and tags) along with the objects necessary to complete their histories, from specified repo(s). If no refspecs are given on the command line, as on this item, the refs to fetch are read from remote.<remote>.fetch variables instead. E.g. +refs/heads/*:refs/remotes/origin/*

git checkout --ours conflictedFile.js

During a conflict resolution, choose the "ours" (i.e. the current branch's) version of the lines for all conflicts in the specified file. Similarly "theirs".

git pull <remote>

Fetch the specified remote's copy of the current branch and immediately merge it into the local copy. This is the same as git fetch <remote> followed by git merge origin/<current-branch>.

git branch -D <branch>

Force delete the specified branch, even if it has unmerged changes. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development.

git revert <commit>

Generate a new commit that undoes all of the changes introduced in <commit>, then apply it to the current branch.

git reflog

Git keeps track of updates to the tips of branches, and other refs such as HEAD, using a mechanism called reflog. This allows you to go back to a commit even though it's not referenced by any branch or tag. After rewriting history, the reflog contains information about the old state of branches and enables you to go back to that state if necessary.

git pull

Incorporate changes from a remote repository into the current branch; in default mode, fetch and then merge.

git init --bare <directory>

Initialize an empty Git repository, but omit the working directory. Shared repositories should always be created with the --bare flag (see discussion below). Conventionally, repositories initialized with the --bare flag end in .git. For example, the bare version of a repository called my-project should be stored in a directory called my-project.git.

git init

Initializes a new Git repository. Creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the .git directory, an existing project remains unaltered.

git pull --rebase <remote>

Instead of using git merge to integrate the remote branch with the local one, use git rebase.

git branch -a

List all branches, including remote-tracking branches (as well as local branches).

git config --list

List all the git config settings, including username and email address.

git branch

List the (local) branches in your repository

git merge --no-ff <branch>

Merge the specified branch into the current branch, but always generate a merge commit (even if it was a fast-forward merge). This is useful for documenting all merges that occur in your repository.

git merge

Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. Note that all of the commands presented below merge into the current branch. The current branch will be updated to reflect the merge, but the target branch will be completely unaffected. Again, this means that git merge is often used in conjunction with git checkout for selecting the current branch and git branch -d for deleting the obsolete target branch.

git stash

Move changes from a dirty working directory and index to a stash stack. Resets the working directory to match the HEAD commit (using git reset --hard).

git reset --hard <commit>

Move the current branch tip (backward typically) to <commit> and reset both the staging area and the working directory to match.

git reset <commit>

Move the current branch tip (backward typically) to <commit>, reset the staging area to match, but leave the working directory alone.

git checkout (wrt branches)

Navigate between the branches created by git branch. Checking out a branch updates the files in the index and working directory to match the version stored at the tip of that branch, and it tells Git to record future commits on that branch. Think of it as a way to select which line of development you're working on.

When should revert be used?

Reverting should be used when you want to undo the effect of one or more commits. This can be useful, for example, if you find that some commits were erroneous, and you don't want to reset or rebase because descendant commits have been published. Instead of manually fixing and committing the changes, you can use git revert to automate the process and do it in a more uniform and predictable way.

git checkout -b <branch-A> <branch-B>

Same as 'git checkout -b <branch-A>' but base the new branch off of <branch-B> instead of the current branch.

git fetch <remote> <branch>

Same as 'git fetch <remote>' but only fetch the specified branch.

git push <remote> --force

Same as 'git push <remote> <branch>' but force the push even if it results in a non-fast-forward merge. Do not use the --force flag unless you're absolutely sure you know what you're doing.

git log --author="<pattern>"

Search for commits by a particular author. The <pattern> argument can be a plain string or a regular expression.

git log --grep="<pattern>"

Search for commits with a commit message that matches <pattern> , which can be a plain string or a regular expression.

git push <remote> <tag-name>

Send specified tag to remote repository, along with all objects necessary to complete it.

git checkout

Serves three distinct functions: 1 - checking out files, 2 - checking out commits 3 - checking out branches. Checking out a commit makes the entire working directory match that commit. This can be used to view an old state of your project without altering your current state in any way. Checking out a file lets you see an old version of that particular file, leaving the rest of your working directory untouched.

git remote -v

Show a detailed list of the remotes that you currently have set up.

git log --merges

Show a log consisting only of merge commits. (Not to be confused with --merge!)

git log -n <limit> OR git log -<limit>

Show at most <limit> commits.

git log --oneline

Show log, condensing output about each commit to a single line. This is useful for getting a high-level overview of the project history.

git log <since>..<until>

Show only commits that occur between <since> and <until>. Both arguments can be either a commit ID, a branch name, HEAD, or any other kind of revision reference.

git reflog --relative-date

Show the reflog with relative date information (e.g. 2 weeks ago).

git init --bare

The --bare flag to the git init command creates a repository that doesn't have a working directory, making it impossible to edit files and commit changes in that repository. Central repositories should always be created as bare repositories because pushing branches to a non-bare repository has the potential to overwrite changes. Think of --bare as a way to mark a repository as a storage facility, as opposed to a development environment. This means that for virtually all Git workflows, the central repository is bare, and developers local repositories are non-bare.

git revert

Undoes a committed snapshot. But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content. This prevents Git from losing history, which is important for the integrity of your revision history and for reliable collaboration.

git reset <file>

Unstage changes to the specified file, but leave the working directory unchanged. This unstages a file without overwriting any changes.

git checkout <commit>

Update all files in the working directory to match the specified commit and point HEAD to that commit. Using either a commit hash or a tag as the <commit> argument, instead of a branch, will put you in a detached HEAD state.


संबंधित स्टडी सेट्स

Exam 1 (Ch. 2: Ethics Quiz Questions)

View Set

Pediatrics Infectious diseases and Immunizations Quiz ?'s

View Set

Is it mutually exclusive AND exhaustive?

View Set

Soc 101: Chapter 15.1: Population

View Set

Chapter 15 ~ Aggregate Demand and Aggregate Supply

View Set

1999 ap government test and answers

View Set

CYBR1.CAB-6 Troubleshooting Physical Connectivity (N10-008)

View Set

Anatomy and physiology Chapter 1 midterm review

View Set

Week 4: Chapter 5 : Physical Agents

View Set