Git version management, and contrast the difference between SVN

一、Git vs SVN

Git and SVN which is better what is good, everyone has a different experience.

Git is a distributed, SVN is centralized

This is the biggest difference between Git and SVN. If we can grasp this concept, get to know the most basic difference between the two. Because Git is distributed, so Git support offline work, many operations can be performed locally, including the blockbuster launch will be followed by a branch function. The SVN must be networked to work properly.

Git and more complex concepts, SVN simple and approachable

All control of both Git and SVN developers must admit, Git commands too much, the daily work need to have add, commit, status, fetch, push, rebase, etc., to master, rebase and merge must also master of difference, fetch and pull difference, etc., in addition, there are cherry-pick, submodule, stash and other functions, just listening to these terms they are around.

In this regard the ease of use, SVN for beginners will be more better. But on the other hand see, Git command multi-multi-function means that, if we can grasp the most Git features, appreciate the wonders of which will never go back to find the SVN era.

Git cheap branches, SVN branch expensive

In version management, the branch is very often used functions. Before the release version, you need to publish branch, large development needs, need feature branch, there will be a large team development branch, stable branch and so on. In large team development process, there are often asked to create a branch, and branch switching.

Git branch is a pointer to a commit, the SVN branches are copied directory. This feature allows switching Git branch very quickly, and create very low cost.

And there is a local branch of Git, SVN no local branch. In the actual development process, often encounter some of the code did not finish, but the urgent need to deal with other issues, if we use Git, you can create code that is stored local branch did not finish until the problem has been dealt with, and then back to the local branch continue to complete the code.

Two, Git core concepts

The core is a concept Git workflow.

  • Workspace (Workspace) is a computer in the actual directory.
  • Staging area (Index) similar to the cache area, temporarily save your changes.
  • Warehouse District (Repository), divided into local and remote warehouse warehouse.

Switched from SVN to Git, the most difficult to understand, and most do not understand is the staging area and local warehouses. Skilled use Git, will find that this is simply God's design, due to the existence of both, so a lot of work to become manageable.

Usually submit the code several steps:

  1. git add submission from the work area to the staging area
  2. git commit to submit to a local warehouse from scratch
  3. git push or git svn dcommit submitted from the local warehouse to the remote repository

In general, remember the following command, you can perform daily work (Photo from Internet):

 

 

 

Three, Git-SVN commonly used commands

If the server uses SVN, Git but want to experience the local branch of local, offline operation and other functions, you can use Git-SVN function.

 

 

 [ Git-SVN ]

# Download a SVN project and its entire code history, and is initialized to Git repository 
$ git svn clone - S [Repository]
 # view the current situation repository 
$ git svn info
 # retrieve remote repository changes in all branches 
$ git svn fetch
 # retrieve remote that changes the current branch, rebase and merge with the local branch 
$ git svn rebase
 # upload the current local repository branch to the remote repository 
$ git svn dcommit
 # pull new branch, and submit to a remote repository 
$ svn copy [ remote_branch] [new_remote_branch] - m [Message]
 # creating local branch corresponding remote branch 
$ git checkout -b [local_branch] [ remote_branch]

Fourth, the initialization

From the beginning of this section, unless otherwise noted, the following commands are applicable to Git and GIT- SVN.

# In the current directory to create a new Git repository 
$ git the init
 # downloading a project and its entire code history [Git only] 
$ git clone [url]

5, configuration

# Enumerate all configuration 
$ git config - L
 # to configure an alias command 
$ git config - , Ltd. Free Join alias.co Checkout
$ git config --global alias.ci commit
$ git config --global alias.st status
Git config $ - , Ltd. Free Join alias.br Branch
 # user information when setting submit code 
$ git config [- , Ltd. Free Join ] user.name " [name] " 
$ git config [ - , Ltd. Free Join ] user.email " [Email address] "

Git user profile is located ~ / .gitconfig

Git repository single configuration file located in ~ / $ PROJECT_PATH / .git / config

Sixth, add or remove files

# All files add the current directory to the staging area 
$ git the Add.
 # Adds the specified files to the staging area 
$ git the Add <file1> <file2> ...
 # Adds the specified directory to the staging area, including its subdirectories
$ git add <dir>
# Delete a workspace file and delete the staging area into a 
$ git RM [file1] [file2] ...
 # stop tracking 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]

Add the file name file1 to .gitignore file, Git will stop tracking file1 state.

Seven branch

# List all local branches 
$ git Branch
 # 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 switch to the branch 
$ Git Checkout -b [new_branch] [remote- branch]
 # switched to a specified branch, and updates the work area 
$ Git Checkout [branch- name]
 # merging branches to the current branch 
$ Git merge [branch]
 # selecting a commit , incorporated into the current branch 
$ git cherry- Pick [the commit]
 # delete local branch, -D parameter to force the removal branch 
$ git branch -d [branch- name]
 # delete remote branch 
$ git push [remote]: [ remote-branch]

Eight, submitted

# Submitted to the staging area warehouse district 
$ git the commit - m [the Message]
 # submit change the work area and temporary area directly to the warehouse district 
$ git the commit - A
 # show all diff when submitting information 
$ git the commit - v
 # submit temporarily memory area changes to the warehouse district, merged last modified, and last modification of information submitted 
$ git --amend the commit - m [the message]
 # Upload a local branch to a specified remote repository 
$ git push [remote] [remote -branch]

Nine, pull

# Download remote repository of all changes (Git only) 
$ git FETCH [Remote]
 # displays all remote repository (Git only) 
$ git Remote - v
 # Display information to a remote repository (Git only) 
$ git Remote Show [Remote]
 # add a new remote repository, and name (Git only) 
$ git the Add remote [remote- name] [url]
 # fetch change remote repository, and merge with the local branch, (Git only), if used Git-SVN Please see Section 
$ git pull [remote] [branch]
 # fetch remote repository changes, and with the local branch rebase merge, (Git only), if used Git-SVN, please see Section III 
$ git pull --rebase [remote] [branch]

Ten, revocation

# Restore files to the staging area designated work area 
$ git Checkout [File]
 # all the files in the current directory restore staging area to the work area 
$ git Checkout.
 # Restore the work area to specify the commit 
$ git Checkout [the commit]
 # Reset specified file temporary area, with the last commit consistent, but the work area unchanged 
$ git the rESET [file]
 # reset the staging area to the work area, and consistent with the last commit 
$ git the 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 the rESET [commit]
 # reset the current branch HEAD specified commit, at the same time to reset the staging area and working area, designated commit consistent with 
$ git the RESET - Hard [the commit]
 # Create a new commit, to revoke the designation of the commit 
$ git Revert [the commit]
 # will change uncommitted on the storage area 
$ git stash
 # restore the contents of the storage area to the current workspace
$ git stash pop

XI inquiry

# View workspace files to modify the state 
$ git Status
 # View workspace files to modify the specific content of 
$ git diff [File]
 # view the staging area file content 
$ git diff - cached [File]
 # view the change log repository 
$ git log
 # see someone commit record 
$ git log --author = someone
 # view the history of a file specific content 
$ git log - the p-[file]
 # view a commit specific content 
$ git show [commit]

  

Guess you like

Origin www.cnblogs.com/zengming/p/12425001.html