Learning is the http://www.liaoxuefeng.com/of Liu Xuefeng teacher, the Git tutorial.
Here to organize the study notes for their own later review, hope to complete learning git, please go to the above Web site to find git tutorials, very good learning materials.
To Create a repository :git init
(1) adding files to the Git repository :
First step:git add <file> add files to staging area.
Step two:git commit-m " commit instructions " to the workspace.
(2) view Git repository Status:
git Status View warehouse current status
git diff to see what's changed
git log to view the commit log, plus --pretty=oneline to display one commit in a row, plus --graph to see the branch graph.
git reflog view command history
(3) version fallback:
git reset--hard commit_id fallback to the specified version
(commit_id is The specified version number, where HEAD represents the current version,head^ is the previous version,head^^ is the last version,head~ it is up to the last three versions. )
Undo Changes:
1.git checkout--file discard changes to a file if the file is not added to the staging area. (git checkout replaces the workspace version with the version in the repository.) can be used to undo the deletion and modification of the workspace. )
2. to undo the modification of a file that has already been added to the cache, git reset HEAD file revokes the staging area modification and then uses git checkout--file to discard changes to the file on the workspace.
3. The changes that have been submitted are directly rolled back to the pre-modified version.
(4) Delete files:
Delete files from repository:git rm file Delete, and git commit
(5) Remote library:
Using Github 's git hosting services:
SSH keyneeds to be created on GitHub account because the local git repository and GitHub The warehouse file transfer is encrypted via ssh , andGithub identifies the source of the push via the ssh public key. A Github account can add multiple SSH keysto work with multiple devices.
To associate a remote library:
Pushes the contents of the local warehouse to the remote library.
1. First create a new repository on your GitHub account.
2. use the command on the local repository:git Remote add Origin[email protected]:p ath/repo-name.git
Associate a remote library.
3. Push all content for the master branch for the first time:git push-u Origin master
Post-push:git push Origin master
The first push will trigger an SSH Warning, just be sure.
To create a remote warehouse with the correct posture:
1. Create a new repository on your GitHub account.
2. Clone remote repository to Local:git clone [email protected]:p ath/repo-name.git
The address format here is the native git protocol supported by SSH , which is a faster one. Of course we can also use the HTTPS protocol. is the address of the git remote repository on the Web page.
(6) use of branches :
git branch view branches
git branch <name> creating a branch
git checkout <name> switch branches
git checkout-b <name> create + Toggle Branch
git merge <name> merge a branch to the current branch
git branch-d <name> Delete Branch
(7) resolution of the conflict:
When Git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.
You can see the branch merge diagram with the git log--graph command.
Merging branches, plus the --no-ff parameter can be combined with the normal mode, the merged history has branches, can see that there has been a merger, and Fast forward merge will not be seen to have been merged.
(8) Staging management:
When fixing a bug , we fix it by creating a new bug Branch, then merging and finally deleting the branch.
When the work is not finished, first put the work site git stash , and then go to fix the bug, repair, then git stash pop(equivalent to git Stash apply Restore, then use git stash drop to delete), back to the job site.
git stash list can be used to view the saved work site, can be saved multiple times, when need to restore, you need to specify the recovery of stash, commands such as: git stash apply [email Protected]{0}.
To develop a new feature, it is best to create a new branch. If you want to discard a branch that has not been merged, you can use git branch-d <name> forcibly delete it.
(9) push files to remote library:
git remote-v view Remote Library information.
git push Origin branch-name from the local push branch, if the push fails, first crawl The remote new commit with Git pull, then merge locally, resolve the conflict, and then push.
git checkout-b branch-name origin/branch-name Local and Remote branch branches, the names of local and remote branches are best consistent.
git branch--set-upstream branch-name origin/branch-name Establish the association of local and remote branches.
(Ten) label Management :
To create a label:
git tag <name> [commit_id] Create a new label, default to HEAD, or you can specify a commit ID;
git tag-a <tagname>-M " description information " specifies tag information;
Git tag-s <tagname>-M " description information " with PGP signature tag;
git tag to view all tags.
git push origin <tagname> push a local tag;
git push Origin--tags pushes all the local tags that have not been pushed;
To delete a label:
git tag-d <tagname> delete a local tag;
git push origin:refs/tags/<tagname> deletes a remote tag.
use GitHub to contribute code to someone else's Open Source Library:
On GitHub , you can Fork the open source Warehouse;
Own the Fork after the warehouse read and write permission;
3 You can push pull request to the official warehouse to contribute code.
Ignore special files:
When you omit certain files, you need to write . Gitignore.
The. Gitignore file itself is put into the repository and can be versioned for . Gitignore .
Git Learning Notes