Git distributed version control system, very abuse of a version of the management system, this post describes the common GIT commands, for not GIT version control of the rookie, for the maintenance of the GIT server Daniel, kneeling for advice, in fact, I am also a rookie.
Git is the product of oppression, because BitMover company withdrew the version control system BitKeeper free access to the Linux community, and the development of Linux urgently needs a good distributed version control system, Our arrogant proud of the father of Linux Linus unwilling to BitMover bow pay, a lifetime of gas spent less than one months of time with their C write out the most popular distributed version control system git, here is very grateful to BitMover Company's promotion, with the now very useful git , do not say, Linus is still very abuses.
1. Set your name and email in git these are the signatures at the time of committing the commit.
git config--global user.name "Yatian"
git config--global user.email "[Email protected]"
2. Create a version library.
# First find the right place to create an empty folder
mkdir Learngit
# Use GIT commands to turn this directory into a repository that git can manage
Git init
Note: After executing the git init command, you will be prompted to create an empty warehouse, and there is a hidden file '. Git ', which is a tracking management repository, it's OK not to manually modify this file, easy to make the repository bad.
# Write a file Readme.txt must be placed in the Learngit directory, otherwise in this warehouse is not found
git add readme.txt
# tell Git to submit the file to the repository
Git commit-m "wrote a Readme file"
-M is here to explain this operation, convenient to find history later
# view current git has no modified files and newly uploaded files
git status
# View files are those that have been modified and reviewed in detail
Git diff readme.txt
# will already exist file, modified after submission method
Git commit-a-M "Lanyulei"
# query Git for all changes to record commands
git log [--pretty=oneline]
There may be too much content for the git log input to be executed separately, plus the following parameters can be briefly entered. "[]" stands for dispensable
# fallback version, first of all, Git must know which version of the current version, in Git, with the head of the current version, that is, the latest commit 3628164 ... 882E1E0 (Note that my submission ID and your affirmation is not the same), the previous version is head^, the last version is head^^, of course, to 100 versions write 100 ^ more easy to count, so written head~100.
Fallback to previous version
git reset--hard head^
If you want to go back, it is also possible, but the premise is that you can remember the previous commit id,git always regret to eat, you can use Git reflog to see your history operation
Git reflog
git reset--hard 123456
# The latest version comparison in Workspace version and repository
git diff HEAD--readme.txt
# Discard the workspace changes, just want to just modify things, restore
Git checkout--readme.txt
# When you want to roll back the changes in the staging area, use the command
git reset HEAD file
# When you delete a job and go to a file, git status will prompt you for inconsistencies between the workspace and the version area, one that you really want to remove from the repository
git rm file
git commit-m "Delete file"
Second, you mistakenly deleted the workspace files, you want to restore, then undo the work area changes can be
Git checkout--file
3. Remote Storage
# Create a shared repository by creating your own account for the GitHub site
# to associate a remote code base
git remote add origin [email protected]:yatian/test.git
The name of the Origin remote library is the default in Git, and can be something else
# Push code to the remote library
git push [--force]-U Origin Master
Note: When you submit a second time, you can submit it directly
Git push Origin Master
# Clone Code
git clone [email protected]:yatian/gitskills.git
4. Branch Management
# Create a new branch and switch to this new branch
git checkout-b Dev
The git checkout command plus the-b parameter means create and switch, equivalent to the following two commands:
Git branch Dev
git checkout Dev
# View your current branch
Git branch
# Merge a branch into the current branch
git merge Dev
# Delete Branch
git branch-d Dev
Git common Commands introduction