Version Control Tools - GIT - Basic Commands

install git

Install GIT on Linux

Install GIT on Mac OS X

There are two ways to install Git.

One is to install homebrew, and then install Git through homebrew. For details, please refer to homebrew's documentation: http://brew.sh/ .

The second method is simpler and the recommended method is to install Xcode directly from the AppStore. Xcode integrates Git, but it is not installed by default. You need to run Xcode, select the menu "Xcode" -> "Preferences", and find it in the pop-up window. "Downloads", select "Command Line Tools", click "Install" to complete the installation.

Install GIT on Windows

Repository acquisition and modification

Initialize a directory as a Git repository

$ git init

Initialized empty Git repository in /opt/konnichiwa/.git/
# Initialize an empty Git repository in the /opt/konnichiwa/.git directory.
$ ls -a
 . . . git README hello.rb
 Copy a Git repository
$ git clone git://github.com/schacon/simplegit.git
Initialized empty Git repository in /private/tmp/simplegit/.git/
remote: Counting objects: 100, done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 100 (delta 35), reused 0 (delta 0)
Receiving objects: 100% (100/100), 9.51 KiB, done.
Resolving deltas: 100% (35/35), done.
$ cd simplegit/
$ ls
README   Rakefile lib

Modify the remote warehouse address
Method
 1: Modify the command $ git remote origin set-url [url]
 Method 2: Delete first and then change
 $ git remote rm origin
$ git remote add origin [add]
Method 3: Modify the Config file directly

View the current remote library
$ git remote -v
origin git://github.com/xx/xx.git

Add remote repository
$ git remote
$ git remote add pb git://github.com/xx/xx.git (rename to pb)
$ git remote -v
origin git://github.com/xx/xx.git
pb git://git.com/xx/xx.git

Deletion and renaming of remote repositories
$ git remote rename pb paul
$ git remote
$ git remote rm paul


 

basic snapshot

add file to cache
$ git add xx (add file to cache)
$ git status -s (to see the status of files in the working directory and cache)
$ git diff (shows the difference between changes that have been written to the cache and changes that have been modified but not yet written to the cache)
$ git diff --cached (to see cached changes)
$ git diff HEAD (see all cached and uncached changes)
$ git diff --stat (show summary instead of whole diff)
Take a snapshot of the cached content
--Git records name and email address for each commit
$ git config --global user.name 'Your name'
$ git config --global user.email '[email protected]'
--commit actual storage snapshot -m:comment
$ git commit -m 'my xxx changes'
-- Automatically put the recorded and modified files into the cache area before committing
$ git commit -a -m 'my xxx changes'
Uncache cached content
--Cancel the addition of the previous git add
$ git reset HEAD --file
remove file from cache
$ git mv

Branch and Merge

List, create and manage work contexts
$ git branch (list branches)
$ git branch xx (create xx branch)
$ git branch -b xx (create xx branch and switch to xx branch)
$ git branch -d xx (delete xx branch)
switch to new branch context
$ git checkout xx (switch to xx branch)
$ git checkout -b xx (create xx branch and switch to xx branch)
merge branch
$ git merge xx (merge the xx branch content with the current branch content)
merge conflict
$ git diff (to see conflicting content)
$ git add
$ git commit
Displays a record of changes committed in a branch
$ git log (to view the change log of the current branch)
$ git log --oneline
$ git log --oneline --graph

Share and update projects

List, add and delete remote repository aliases
$ git remote
$ git remote -v
$ git remote add
$ git remote rm
Download new branches and data from remote warehouses (manual merge is required)
$ git fetch [alias]/[branch]
Pull data from remote repository and merge into current branch
$ git pull
Push new branches and data to a remote repository
$ git push [alias]/[branch] (push local [branch] branch to [alias] remote [branch] branch)
--Commit branch conflict resolution
$ git fetch [alias]
$ git merge xx/xx
$ git push [alias] [branch] (push local changes to remote repository)

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327004084&siteId=291194637