Git common commands initialize the repository
PS: The command will create a. git directory, but will not proactively incorporate the files in the existing project (you need to add them yourself);
Four status of files
Untracked not tracked
The following actions arrive at the non-tracked status:
新建文件 vi aaa从索引区删除文件 git rm
Unmodified unmodified the following operations arrive in the unmodified state:
git commit
Modified modified
To reach the modified state:
vi aaa
Staged has been staged
添加 git add
View current status
Current status
git status
Status overview
git status -s
PS: ' MM ' mark: Left M: Modified and put into the staging area, right m: modified not yet put into staging area
Three working areas
- Git repository
- Working directory
- Staging Area
Basic Git Workflow
Modify the file in the working directory.
vi aaa
Staging file, placing a snapshot of the file into the staging area.
git add .
Commit the update, locate the file in the staging area, and permanently store the snapshot in the Git repository directory.
Tracked file modifications are submitted directly to the library:
git commit -a -m "update file aaa" aaa
Remove files from
Remove files from Staging area (also deleted on hard disk)
Remove files from Staging area (keep on hard disk, this file is no longer tracked)
Moving files
Operation of the staging area
Submit Staging
Supplemental Submissions
It will only show up as a commit at the end
Cancel Staging
git reset HEAD readme
Change the Readme file from the staging state to the non-tracked state
Fallback to the specified version
git reset --hard :commit_hash_id
View commit History
View Logs
git log
Show content differences for the last two commits
Single-line display
$git log --pretty=oneline $git log --oneline --decorate$git log --pretty=format:"%h - %an, %ar : %s" 8029c4c - colin, 10 days ago : add redis_gallery_ad_impr
View submission records only for the specified submitter
$ git log --committer=colin
Remote Warehouse Operations
View Remote repositories
Update local remote warehouse data pull (not automatically merged into the current working directory):
git fetch origin git merge origin/serverfix 将origin/serverfix合并到当前的分支
Remote data is pulled and merged into the current directory:
git pull origin
Automatically pulls and merges data to the trace branch of the remote origin
Push to remote Warehouse
Push the local Serverfix branch as the Serverfix branch of the remote repository
Branching operations Creating branches
git branch testing
Branch switching
Switch to a branch that already exists (HEAD points to this branch)
git checkout testing
New and toggle
Create a new branch based on the current directory and switch the workspace to the new branch:
git checkout -b iss53
Create a new branch of Serverfix based on the remote repository origin:
git fetch origin git checkout -b serverfix origin/serverfix or: git checkout --track origin/serverfix
Trace Branch
Set trace settings an existing local branch tracks a remote branch that has just been pulled down, or wants to modify the upstream branch being traced:
git branch -u origin/serverfix
Query tracking Relationship View all trace branches of the setting
git branch -vv
Delete Branch
Branch Merge
Merging merge Merge Iss53 branch to Master Branch (PS: The merged branch is the current workspace)
git checkout mastergit merge iss53
A variable-base rebase is a sequence of commits that are applied to another branch in the order in which they were originally ordered, and the merge is the final result combined.
git checkout experimentgit rebase master
View the current branch list
git branch
Ref: "Pro Git 2.0"
Posted by: Big CC | 14may,2016 Blog: blog.me115.com [subscribe to]github: Big cc
Common git commands