[] Rapid collaborative development using git

1、git config

Configuring user information only once:

$ git config --global user.name "John Doe": Set the user name
$ git config --global user.email [email protected]: Set the user's mailbox
$ git config --list: check the configuration of an existing
$ git config user.name: direct access to set an environment variable

If the --globaloption is to change the configuration file that is located, after all your projects will use the default user information configured here under your user home directory. If you want to use a different name or e-mail in a particular project, as long as remove --globalthe option to re-configure new settings saved in the current project .git/configfile.
Sometimes see duplicate variable name, it shows that they come from different configuration files (such as /etc/gitconfigand ~/.gitconfig), but in the end Git actually used the last one.

2、git init

Create a Git repository in the current directory

$ git initCommand: In the current directory to create a new Git repository
$ ls -lacommand: show .git directory you just created
$ touch index.htmlor touch sttyle.csscommand: new .html and .css files in this directory,

3、git add

Add all files in the current directory to the staging area

$ git add: All files in the current directory are added to the staging area
$ git add [file1] [file2]: Adds the specified files to the staging area
$ git add [dir]: Adds the specified directory to the staging area, including subdirectories
$ git add .: Before adding each change, will be asked to confirm
$ git add -p: for the same multiple file changes, can achieve sub commits
$ git status -sb: You can see the green in front of a, mean that we have successfully added the git commit -m"submit information" will just add to the contents of the temporary area formally submitted to the local repository (.git)

4、git commit -v

Display all information submitted diff

$ git commit -v: Display all information submitted diff

5、git push origin

$ git push origin: The current branch push origin host corresponding branch
$ git push -u origin master: The above command master branch pushed to the origin host specifying the origin as the default master, the latter can be used without any use git push the
$ git push: default push up only the current branch, this is called simple way. In addition, there is a matching way, will have to push all of the local branch of the corresponding remote branch. Prior to Git version 2.0, defaults to matching method, is now default to simple.

6、git remote

Add remote warehouse

  • We can add multiple remote repository to manage a local library. Used for data backup, or on-line warehouse management operations. For example, we can market the project
    to create multiple versions of the warehouse project.

+ develop development repository
+ test test warehouse
+ release issued warehouse

  • For different warehouses, different permissions can be controlled.
  • develop warehouse development, it may be all operations personnel can have permission to modify, you can operate
  • test test warehouse, testers would only be able to view, as well as for its contents to be modified.
  • release distribution warehouse, this would only be a warehouse operation and maintenance, or some managers to have access to. The warehouse itself, there are some differences in the configuration. Most people can not see, to the security control data online, to avoid leakage.
  • operating
$ git remote add develop master
$ git remote add test master
$ git remote add release master

Such native code, the association will be three different warehouses. So when we submit code, specifically to be submitted to it which remote branch. This time, we need to clear the remote branch when push.

$ git push develop master
$ git push test master
$ git push release master
  • In most cases, we are all submitted code in a remote branch, only occasionally be useful to submit to different remote warehouse
    . So there is an easier way to submit. That is associated with the local branch of a remote repository branch. Use git branch --set-upstream-tocommand.
$ git branch --set-upstream-to develop master 或者 git branch -u develop master

In this way, simply follow the use git pushor git pullcommand it.

7, commonly used commands

First, the general configuration

# View the current git version information

git --version

# Get the current user's user name

git config --global user.name

# Get current logged in user mailboxes

git config --global user.email

# Configure with vim editor of Global linux

git config -e

Second, git log in

# Set git user account name

git config --global user.name "your-user-name"

# Set git-mail account user

git config --global user.email "your-user-email"

Third, the new code base

# Create a git repository in the current directory

git init

# Create a new directory and initialize it to a git repository

git init [project-name]

# Download a project and save it all log

git clone [url]

A branch # download the project and all of the log

git clone -b [branch-name] [url]

Fourth, add / delete files

# Add the files to the staging area

git add [file-name]

# Add all files in the current directory to the staging area

git add .

# Add multiple files to the staging area

git add [file1] [file2] [file3] …

# Will add all files to the staging area

git add -a

git add *

# Delete a workspace file, and put this to delete staging area

git rm [file1] [file2] [file3] …

# Modify the file name, and this operation into the staging area

git mv [file-original] [file-renamed]

Fifth, the code submission

# The contents of the temporary area added to the repository (warehouse district)

git commit -m "Remarks Information"

# File submitted to the staging area designated repository (warehouse district)

git commit [file1] [file2] [file3] ... m "Information Notes"

Sixth, branch management

# 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 use the current branch, not the switching action

git branch [branch-name]

# Creating a new branch, and the switching current branch for the branch

git checkout -b [branch]

# Handover branch, and update the work area

git checkout [branch-name]

# Switch to the previous branch

git branch -

# Delete branch

git branch -d [branch-name]

# Delete remote branch

git push origin --delete [branch-name]

git branch -mr [remote/branch]

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 commit changed files every time a

git log --stat

# Commit history keyword search

git log -S [keyword]

# Show version history of a file

git log --follow [file]

git whatchanged [file]

# Display all submitted and the number of submitted

git shortlog -sn

# Show staging area code differences and work area

git diff

# Shows the difference between the work area and the current branch newest commit

git diff HEAD

# Display a commit metadata and content changes

git show [commit]

# Display the recent submission

Go reflog

Eight, remote synchronization

# Download all the changes remote repository

git fetch [remote]

# Display all the remote repository

git remote -v

# Remote warehouse and a new name

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

# Remote repository to push all branches

git push [remote] --all

Nine, revocation

# 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 files to the staging area of ​​the workspace

git checkout .

# Reset the staging area of ​​the specified file, with the last commit consistent, but the same workspace

git reset [file]

# Reset the staging area to the work area, and the last commit consistent

git reset --hard

# Reset the current branch pointer for the specified commit, at the same time to reset the staging area, but the same work area

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

git reset --hard [commit]

# Reset the current HEAD to the specified commit, but remain unchanged staging area and working area

git reset --keep [commit]

# Create a new commit, commit to revoke the designation

# All changes which will be offset by the former, and applied to the current branch

git revert [commit]

# Temporarily change uncommitted removed, and then later moved

git stash

git stash pop

set:

Behind by one point is add all files in that directory git add .

add notes git commit -m "提交注释"

Submitted on git git push origin master

Reference article: https://blog.csdn.net/JackLiu16/article/details/80952650

Published 20 original articles · won praise 1 · views 568

Guess you like

Origin blog.csdn.net/weixin_42295814/article/details/102739637