git use study notes

About ## Git
Workspace: Workspace
Index / Stage: staging area
Repository: warehouse district (or local warehouse)
Remote: remote repository
## a, the new code libraries
# Create a Git repository in the current directory
$ git init

# Create a new directory, which is initialized to the Git repository
$ git init [project-name]

# Download a project and its entire code history
$ git clone [url]

## Second, the configuration
#Git settings file to .gitconfig, it can (global configuration) in the user's home directory, you can also (project configuration) in the project directory.

# Display the current configuration Git
$ git config --list

# Edit the configuration file Git
$ git config -e [--global]

# Set the user information when submitting the code
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[Email address]"

## Third, add / delete file
# Adds the specified files to the staging area
$ git add [file1] [file2 ] ...

# Adds the specified directory to the staging area, including subdirectories
$ git add [dir]

# Add all the files in the current directory to the staging area
$ git add.

# Before adding each change, will require confirmation
# for many changes in the same file, can achieve sub commits
$ git add -p

# Delete a workspace file and delete the staging area into a
$ git rm [file1] [file2 ] ...

# Stop following the specified file, but the file remains in the work area
$ git rm --cached [file]

# Rename files, and this will be renamed into the staging area
$ git mv [file-original] [file-renamed]

## Fourth, submit the code
# submitted to the staging area warehouse district
$ git commit -m [message]

# Submit files to the staging area designated warehouse district
$ git commit [file1] [file2 ] ... -m [message]

# Workspace submit changes since the last commit directly to the warehouse district
$ git commit -a

Diff displays all information submitted #
$ git commit -v

# Use a new commit, replace the previous commit
# If the code does not have any new changes, then submit the information to commit a rewrite of the
$ git commit --amend -m [message]

# Redo the last commit, and includes new changes specified file
$ git commit --amend [file1] [ file2] ...

## V. branch
# List all local branches
$ git branch

# List all remote branches
$ git branch -r

# List all local branches and remote branch
$ git branch -a

# Create a new branch, but still remain in the current branch
$ git branch [branch-name]

# Create a branch, and switching to the branch
$ git checkout -b [branch]

# Create a new branch, point to specify the commit
$ git Branch [Branch] [the commit]

# Create a new branch, a tracking relationship with the specified remote branch
$ git branch --track [branch] [ remote-branch]

# Switch to the specified branch, and updates the work area
$ git checkout [branch-name]

# Switch to a branch
$ git checkout -

# Establish trace relationships between existing branches and remote branches specified
$ git branch --set-upstream [branch ] [remote-branch]

# Consolidates branch to the current branch
$ git merge [branch]

# Selecting a commit, incorporated into the current branch
$ git cherry-pick [commit]

# Delete branch
$ git branch -d [branch-name ]

# Delete remote branch
$ git the Push Origin --delete [Branch-name]
$ git Branch -dr [Remote / Branch]

## Sixth, the tag
# lists all Tag
$ git Tag

# Create a tag in the current the commit
$ git tag [tag]

# Create a new tag in the specified the commit
$ git tag [tag] [the commit]

# Delete the local Tag
$ git Tag -d [Tag]

# Delete remote Tag
$ git the Push Origin: refs / Tags / [tagName]

# View information tag
$ git show [tag]

# Submit the specified Tag
$ git the Push [Remote] [Tag]

# Commit all Tag
$ git the Push [Remote] the --tags

# Create a new branch, points to a Tag
$ git Checkout -b [Branch] [Tag]

## Seven, view information
# show there is a change in the file
$ git status

# Display the current version of the history of this branch
$ git log

# Display commit history, and changed files each commit
$ git log --stat

# Search your history based on keywords
$ git log -S [keyword]

# Show all changes after a commit, commit each occupy one line
$ git log [tag] HEAD --pretty = format:% s

# Show all changes after a commit, which "commit" must match the search criteria
$ git log [tag] HEAD --grep feature

# Show version history of a file, including file rename
$ git log --follow [File]
$ git whatchanged [File]

# Display every time the specified file diff-related
$ git log -p [file]

# Show last 5 commits
$ git log -5 --pretty --oneline

# Display all user submitted, sorted by number of commits
$ git shortlog -sn

# Display the file is what people at what time modified
$ git blame [file]

# Show staging area code differences and work area
$ git diff

# Display the staging area and on a difference commit
$ git diff --cached [file]

# Shows the difference between the current workspace and the new branch the commit
$ git diff the HEAD

# Shows the difference between the two commits
$ git diff [first-branch] ... [second-branch]

# Show today how many lines of code you write
$ git diff --shortstat "@ {0 day ago}"

# Display a commit metadata and content changes
$ git show [commit]

# Display a commit file changes
$ git show --name-only [commit ]

# Display when a commit, the contents of a file
$ git show [commit]: [ filename]

# Display the recent submission of branches
$ git reflog

# Pulling the code from the master update the current local branch: branch generally master
$ Git rebase the [Branch]

## Eight, remote synchronization
# All changes download remote repository
$ git fetch [remote]

# Display all the remote repository
$ git remote -v

# Display information about a remote repository
$ git remote show [remote]

# Add a new remote repository, and named
$ git remote add [shortname] [ url]

# Retrieve change remote repository, and merge with the local branch
$ git pull [remote] [branch ]

# Upload a local branch to a specified remote repository
$ git push [remote] [branch ]

# Forcibly push the current branch to a remote warehouse, even if there is a conflict
$ git push [remote] --force

# Push all the branches to the remote repository
$ git push [remote] --all
IX revoked

# Restore files to the staging area designated work area
$ git checkout [file]

# Restore a commit specified files to the staging area and a work area
$ git checkout [commit] [file ]

# Restore all the files in the temporary area to the work area
$ git checkout.

# Reset the specified file temporary area, with the last commit consistent, but the work area unchanged
$ git reset [file]

# Reset the staging area to the work area, and consistent with the last commit
$ git reset --hard

# Reset the current branch pointer for the specified commit, at the same time to reset the staging area, but the work area unchanged
$ git reset [commit]

# Reset the current branch HEAD specified commit, at the same time to reset the staging area and working area, consistent with the specified commit
$ git reset --hard [commit]

# Reset the current HEAD to the specified commit, but keep the staging area and working area unchanged
$ git reset --keep [commit]

# Create a commit, commit to revoke the designation
of all variations # latter will be offset by the former, and applied to the current branch
$ git revert [commit]

# Temporarily change uncommitted removed, and then later moved into the
$ git stash
$ git stash POP

Guess you like

Origin www.cnblogs.com/shichangchun/p/11029119.html