Use Git version control tools in project development to improve efficiency.
Install Git (linux centos platform)
Source code Installation
1. Install dependency
$ Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
2. Compile and install the source code
Address:
Http://git-scm.com/download
Compile and install:
$ Tar-zxf git-1.7.2.2.tar.gz
$ Git-1.7.2.2 cd
$ Make
$ Sudo make install
Binary Package Installation
$ Yum install git-core
Use Git
# Create your own working directory
Sudo mkdir/var/www/site/mycitsm_zyz
Cd/var/www/site/mycitsm_zyz
# Clone code from the code repository
Sudo Gitclone ssh: // username @ ip: port/path/to/example. git/path/to/workdir
# Clone the code to your working directory and set the information to help identify the update source.
$ Git config user. name "username"
$ Git config user. email username@example.com
# Ignore certain files
Create and edit the. gitignore file in the working directory, and write the content you want to ignore.
Example:
$ Cat. gitignore
*. Pyc
*. Pyo
Test _*
*. Bak
Then you can edit and submit the code in your working directory.
General Workflow
# Update code
$ Vim/path/to/file
# Viewing File status
$ Git status
# Temporary update
$ Git add/path/to/file
# Submit updates locally
$ Git commit-m "Description"
Or pass
$ Git commit-v: write more detailed submission instructions and record specific updates.
# Push local updates to a remote Repository
$ Git push origin master (origin is the assumed remote repository name, master is the default Branch)
# Pull new content from remote Repository
$ Git pull origin
# Getting help
$ Git help
# Create a branch
$ Git branch branchname
# Switch Branch
$ Git checkout branchname
# The preceding two steps can be merged into one step.
$ Git checkout-B branchname
# Merge branches
Switch back to master branch $ git checkout master
Merge the branches to the main branch $ git merge branchname
# View branches
$ Git branch
# View only unmerged branches
$ Git branch -- no-merged
# View only merged branches
$ Git branch -- merged
# Delete a branch (merged)
$ Git branch-d branchname
# Delete a branch (whether merged or not)
$ Git branch-D branchname
# View the differences between unsaved files and those before modification
$ Git diff
# View the difference between the saved files and the snapshot that was last submitted
$ Git diff -- cached
# Removing files
$ Git rm/path/to/file
# Only deleting from the trail list and not from the working directory
$ Git rm -- cached/path/to/file
# Moving Files
$ Git mv file_from file_to
# View submission history
$ Git log
# Last modification submission
$ Git commit -- amend
# Cancelling saved files
$ Git reset HEAD/path/to/file
# Cancelling modification to a file pair
$ Git checkout --/path/to/file
# Rollback
$ Git reset -- mixed HEAD ~ N
$ Git reset -- soft HEAD ~ N
$ Git reset -- hard HEAD ~ N
N indicates the last N commits. Here it can also be the unique identifier of the version returned after a Commit (which can be obtained through $ git log)
-- Mixed retains the changes and rolls back the commit and index
-- Soft retains the changes, rolls back the commit, and does not roll back the index.
-- Hard is completely rolled back to a specific version.
# View the current remote database
$ Git remote-v
# Pull updates from remote databases
$ Git fetch origin
# Merge pulled update branches to local branches
$ Git merge origin/master
The preceding two steps can be merged into one step.
$ Git pull origin
How to teach Git version control tools
To put it simply, there are three concepts: remote warehouse, local warehouse, and local working directory.
Clone is to down the local repository + working directory from the remote Repository: The local repository is the. git directory in the working directory.
Commit submits modifications to the working directory to the local repository.
Pull returns the remote repository modification to the local repository + working directory.
Push submits modifications to the local repository to the remote repository.
Git Version Control for standalone use
Git inti XXX initializes a Git working directory named XXX
Git status to View File changes in the directory
Git diff
Git commit-a submits modifications. The-a parameter can omit the add step for files that have been tracked, which is convenient.
Git branch-B "XXX" create a branch named XXX about the branch
Switch git checkout XXX to XXX Branch
Gitbranch-d xxx Delete local branch
There are also a lot of questions about how to roll back versions and how to merge branches.
Although a developer may not need commands such as rebase, it is recommended that you learn the local commands and check the Git system.
We recommend that you read the book Pro Git. If you find that it is not used by one person, you can skip this section.