git

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

When should revert be used?

Reverting should be used when you want to remove an entire commit from your project history. This can be useful, for example, if you're tracking down a bug and find that it was introduced by a single commit. Instead of manually going in, fixing it, and committing a new snapshot, you can use git revert to automatically do all of this for you.

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 <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 remote rm <name>

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

git reset <file>

Remove the specified file from the staging area, but leave the working directory unchanged. This unstages a file without overwriting any changes.

git clean -df

Remove untracked files and untracked directories from the current directory.

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 untracked folders or files specified by .gitignore.

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 is really more of a convenience command, since it's trivial to see which files are untracked with git status and remove 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 in conjunction with 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 help <command>

Command to display help information about some command

git log -p

Command to display the patch representing each commit

git fetch <remote>

Command to download all the objects and references from a specified repository

git tag <name>

Command to give a name to the last commit

git branch

Command to list all of the branches in your repository

git config --list

Command to list all the settings of your Git, including username and email

git branch -a

Command to list both remote-tracking branches and local branches

git merge <fetched-remote-name> <branch-name>

Command to merge all the files downloaded from the specified repository with into the specified branch

git reset --hard <commit>

Command to move the current branch tip backward to <commit> and reset both the staging area and the working directory to match

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 log

Command to display committed snapshots

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. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit.

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 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 <existing-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 checkout HEAD <file>

Checkout most recent version of <file>

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 stash apply <number-in-list>

Command to apply the changes from the current number in a stash list

git stash list

Command to check out the list of stashes

git diff

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

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

Command to compare two specified branches

git diff <first> <second>

Command to compare two specified branches or commits

git checkout -b <new-branch>

Command to create and check out on the specified branch

git branch -d <branch>

Command to delete the specified branch

git reset <commit>

Command to move the current branch tip backward to <commit>, reset the staging area to match, but leave the working directory alone

git stash pop

Command to pop the last stashed change onto the working directory

git rebase -i <base>

Command to rebase the current branch onto <base>, but use an interactive rebasing session

git rm <file>

Command to remove the file from Git

git reset --hard

Command to reset the staging area and the working directory to match the most recent commit and overwrite all changes in the working directory

git reset

Command to reset the staging area to match the most recent commit, but leave the working directory unchanged

git stash

Command to save all changes without commiting them

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 push <remote> <tag-name>

Command to send specified tag to remote repository

git remote -v

Command to show a list of the remotes that you currently set up

git blame <filename>

Command to show author of code in the specified file

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

Command to show author of current lines of code in the specified file

git log -n <limit>

Command to show limited number of commits

git checkout master

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

git pull

Command to update local repository with what is in remote repository

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 log --oneline

Condense each commit to a single line. This is useful for getting a high-level overview of the project history.

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 a completely 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 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 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 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> (CAPS)

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 tip of branches using a mechanism called reflog. This allows you to go back to changesets even though they are not referenced by any branch or tag. After rewriting history, the reflog contains information about the old state of branches and allows you to go back to that state if necessary.

git merge <branch>

Merge the branch called <branch> into the current branch

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 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 checkout (wrt branches)

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

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 checkout -b <new-branch> <existing-branch>

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

git fetch <remote> <branch>

Same as 'git pull <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 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 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).

--bare

The --bare flag 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, 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.

Esc + :wq

To exit from editor

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 checkout <commit>

Update all files in the working directory to match the specified commit. You can use either a commit hash or a tag as the <commit> argument. This will put you in a detached HEAD state.


Ensembles d'études connexes

Java Software Solutions for AP* Computer Science Test 3.0-3.15

View Set

Finance Chapter 13, Investing in Bonds

View Set

Week 5: Pharmaceutical Benefits Scheme

View Set

Final exam semester 2 Junior English terms

View Set

Personal Health -- Ch. 6: Manage Stress

View Set