Generate ssh key:
-C keygen -t-RSA SSH " [email protected] "
Press Enter three times, and finally get id_rsa id_rsa.pub two files under the folder .ssh.
The private key is id_rsa content, content of id_rsa.pub is the public key.
Here ssh key is generated finished.
git init to create a repository
git the Add the Readme.txt
git the commit
git Status
content changes git diff readme.txt View
Fallback version:
You can use the following two types of commands, the first one is: git reset --hard HEAD ^ So if you want to fall back to the previous version simply HEAD ^ into HEAD ^^ so on.
So, if you want to roll back to before 100 version, use the above method is certainly inconvenient, we can use the following simple command operations: git reset --hard HEAD ~ 100 can be.
git reset --hard version number
git reflog displays the version number of the version number changes every time, and then use a command fallback version
Understand the difference between the work area and temporary area?
Workspace: what you see on the computer directory, such as directory testgit in the file (.git repository directory except hidden). Or later you need to create a new directory files, etc. all belong to the scope of the work area.
Repository (Repository) : the work area has a hidden directory .git, this does not belong to the work area, which is the repository. Where the repository which kept a lot of things, the most important thing is to stage (staging area), and Git automatically creates a master branch first for us, and a pointer HEAD master's.
As we have said using Git submission of documents to the repository has two steps:
The first step: to use git add to add files into it, in fact, is to add the files to the staging area.
Step 2: Use git commit to commit the changes, in fact, is to submit all the contents of the staging area to the current branch.
git checkout - file can be discarded modify the workspace
There are two cases, as follows:
- After readme.txt automatically modified, not into the staging area, use the back and undo changes to the repository exactly the same state.
- Another is already put readme.txt staging area, and then they made the changes, undo changes returned to the state after adding the staging area.
Note: The command git checkout - readme.txt - A very important, if not - then it becomes a command to create a branch
delete
Under normal circumstances, it can be directly in the file directory, delete the file, or use as rm command: rm b.txt, if I want to completely delete the file from the repository, you can then execute commit command out
Before I did not commit, if I want to restore this file in the repository How does it work?
git checkout -- b.txt
Remote repository
git remote add origin warehouse address
The contents of the local repository pushed to the remote, use the git push command, in fact, the current push to the remote master branch.
Because the remote library is empty, the first time we push the master branch, coupled with the -u parameter, Git will not only master the new remote branch content push local master branch, but also the local master branch and remote associated master branch, after the push or pull upon the command can be simplified. After the push, you can immediately see the contents of local and remote databases have been exactly the same as in the github page
From now on, as long as the local made a submission, you can adopt the following commands:
git push origin master
Six: create and merge branches.
git checkout command with the -b parameter indicates and switching command is equivalent to the following two
git branch dev
git checkout dev
Merge branch
git merge branch name
Deleted branches
gitbranch -d 分知名
Summary command to create and merge branches as follows:
View branch: git branch
Creating a branch: git branch name
Handover branch: git checkout name
+ Create a handover branch: git checkout -b name
Merge a branch to the current branch: git merge name
Delete branch: git branch -d name
3. branch management strategy.
Normally merging branches, git general use "Fast forward" mode. In this mode, delete the branch, the branch will lose information, and now we use parameters -no-ff to disable "Fast forward" mode
- Create a dev branch.
- Readme.txt modify content.
- Added to the staging area.
- Switching back to the main branch (master).
- The combined dev branch, use the command git merge -no-ff -m "comment" dev
- View History
git merge --no-ff -m "merge with no--ff" name
branch bug
git stash the current work site can "hide
Create a branch to fix bug bug
After the repair is complete, switch to the master branch, and complete the merge, delete the last branch bug
Restoration work site
git stash apply recovery, after recovery, stash does not delete the content, you need to use the command git stash drop to remove
Another way is to use git stash pop, while restoring the contents of the stash also deleted
Multiplayer cooperative
When you move from a remote library clones when, in fact, Git automatically to the local branch of the master and remote master branch corresponds to it, and the default name of the remote library is origin.
- To view a remote database information using git remote
- To see more information about using a remote repository git remote -v
Push branches:
Branch is to push all the local branch submitted to the remote repository, when pushed, to specify the local branch, so that, Git will branch to the branch pushed to the remote database on the remote corresponding to:
Use the command git push origin master
If we are going to push to the other branches, such as the dev branch, or that we command git push origin dev
So under normal circumstances, those branches to push it?
- master branch is the main branch, and therefore should always be synchronized with the remote.
- Some bug fixes the branch does not need to be pushed to the remote, to be incorporated into the main branch and the main branch to a remote master to push
II: grab branches:
When many people work together, we will push to the master branch on their own changes. Now we can simulate another colleague, you can be on another computer (SSH key note should be added to the github) on the same computer or another clone directory, create a directory called testgit2
Git substantially common commands is as follows:
mkdir: XX (XX refers to create an empty directory directory name)
pwd: displays the current directory path.
git init becomes the current directory can manage the git repository, generate hidden .git file.
git add XX xx to add files to the staging area to go.
git commit -m "XX" behind the submission -m is a comment.
git status to view the status of the warehouse
git diff XX XX view the contents of those files modified
git log to see history
git reset --hard HEAD ^ or git reset --hard HEAD ~ fall back to the previous version
(If you want to fall back to 100 version, use git reset -hard HEAD ~ 100)
cat XX XX view the contents of files
git reflog view the history of the version number id
git checkout - XX XX to undo all the documents in the modified workspace.
git rm XX XX delete files
the Add Remote Origin git https://github.com/tugenhua0707/testgit associated with a remote library
git push -u (-u after the first use is not required) origin master the current master branch pushed to the remote repository
clone git https://github.com/tugenhua0707/testgit cloned from a remote repository
git checkout -b dev create dev branch and switch to the dev branch
View all branches git branch current
git checkout master switch back to the master branch
git merge dev dev branches merged in the current branch
git branch -d dev delete dev branch
git branch name to create branches
git stash to hide the current work, etc. after the recovery site continue to work after
git stash list to see a list of all the hidden files
git stash apply recover hidden files, but does not remove content
git stash drop deleted files
While git stash pop to restore files also delete files
git remote remote view information repository
git remote -v view the remote database details
git push origin master Git master branch will be pushed to the remote database on the remote corresponding to the branch