git self-study summary

After a period of study, on Liao Xuefeng's tutorial: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000


The summary is on my git: https://github.com/blissvisitor/git can follow clone

I finally have a certain understanding of git. During the learning process, according to the tutorial, I learn while doing it. First, I understand the principle, and then I use it proficiently.

Practice makes perfect, learn and learn from time to time, review often, practice constantly, and eventually you will be like an oil seller.


https://git-scm.com //git official website
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 //Liao Xuefeng git tutorial address
//Create a repository
1.cd git //Locate to the specified path
2.git init //Create a new repository
//Submit the version branch
3.git add .git add readme.txt //Save the workspace to the staging area
4.git commit -m "Commit Notes" //Submit all files in the staging area to the warehouse
5.git status //View current warehouse status
6.git diff readme.txt //View file modification content
7.git log //Warehouse modification log
8.git reflog //View all operation logs


//Version rollback


9.git reset --hard HEAD^ //Go back to the previous version-- git reset --hard HEAD^^ //The previous version-- git reset --hard HEAD~100 //Go back to the previous 100 version
10 .git reset --hard version number //back to the specified version
11.git cat readme.txt //view file content
git clean -df //clear all local workspace modifications, and delete added files
//undo Revise


12.git checkout --readme.txt //The workspace is revoked to the previous step
13.git reset HEAD readme.txt //The temporary file is rolled back to the workspace If it is submitted to the repository, it can be rolled back to the previous version (Such as 9)
//Delete the file


14. rm readme.txt //Delete the file or directly find the file to delete Note: After the commit, the version library has been deleted, otherwise the deleted file can be restored to the latest version, but the most recently submitted modification will be Lost (9)
//Remote warehouse


15. ssh-keygen -t rsa -C "your email address" //Create SHH and save it, log in to github, add shh key in settings, copy all the content in id_rsa.pub to the key column, add Complete
16. git remote add origin [email protected]:github account name/local warehouse name.git //Create a new repository on github and associate the existing local repository with it
17. git push -u origin master //local The version library is pushed to the remote library, and it is not necessary to add -u for the first push
. 18. When github ssh pushes for the first time, it will confirm whether the local key is added to the github trust list. Yes, you can
19. git clone remote library address// Clone the remote library to the local, there are various protocols besides native ssh and http (slow speed, input password for each push)
//Branch management


20. git checkout -b dev //Create and switch to the new branch
21. git branch dev //create branch
22. git checkout dev // switch branches
23. git branch // view all branches * as the current branch
24. git merge dev // merge the specified branch to the current branch
25. git branch -d dev // delete the branch git branch -D feature //Forcibly delete branch feature
//Resolve conflicts Multiple branches submit the same file modification, conflicts occur during merging, cannot be merged
quickly When branching, conflicts must be resolved first. After the conflict is resolved, commit again, and the merge is complete.
26. $ git log --graph --pretty=oneline --abbrev-commit //Check the conflict merge situation and delete a branch
27. git merge --no-ff -m "merge with no-ff" dev // Merge the dev branch to the current branch, disable fast forwad
28. git log --graphy --pretty=oneline --abbrev-commit //View the branch merge log
//In actual development, we should follow several basic principles for branch management :
//First of all, the master branch should be very stable, that is, it is only used to release new versions, and you can't usually work on it;
// Where do you work? All work is done on the dev branch, that is to say, the dev branch is unstable. At some point, such as when the 1.0 version is released, the dev branch is merged into the master, and the 1.0 version is released on the master branch;
//Everyone of you and your friends works on the dev branch, everyone has their own branch, and it is enough to merge into the dev branch from time to time.
//bug solution


29 git stash //Store the current branch work site
$ git checkout master //
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 6 commits.
$ git checkout - b issue-101 //Create a bug branch and modify it
Switched to a new branch 'issue-101'
//Modify the bug and submit 
$ git add readme.txt 
$ git commit -m "fix bug 101"
[issue-101 cc17032] fix bug 101
 1 file changed, 1 insertion(+), 1 deletion(-)
//Switch back to branch masterr and merge into master, delete bug branch commit
 $ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/ master' by 2 commits.
$ git merge --no-ff -m "
Merge made by the 'recursive' strategy.
 readme.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git branch -d issue-101
Deleted branch issue-101 (was cc17032).
/ /Switch back to the original working branch
$ git checkout dev
Switched to branch 'dev'
$ git status
# On branch dev
nothing to commit (working directory clean),
//The workspace is clean, where is the work site just now ? Use the git stash list command to see:
$ git stash list
stash@{0}: WIP on dev: 6224937 add merge
//The work site is still there, Git has stored the stash content somewhere, but it needs to be restored, there are two Method:
//One is to use git stash apply to restore, but after restoration, the stash content is not deleted, you need to use git stash drop to delete;
//The other way is to use git stash pop, and restore the stash content at the same time. Deleted:
$ git stash pop
# On branch dev
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: hello.py
#
# Changes not staged for commit:
# (use "git add <file>.. ." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
Dropped refs/stash@{0} (f624f8e5f082f2df2bed8a4e09c12fd2943bdd40)
//Check with git stash list again, and you can't see any stash content:
$ git stash list
//You can stash multiple times. When restoring, use git stash list to check first, and then restore the specified stash. Use the command:
$ git stash apply stash@{0}


//Multiple people collaborate


    to view remote library information, use git remote -v;


    if the newly created branch is not pushed to the remote, it will not be visible to others;


    To push a branch locally, use git push origin branch-name. If the push fails, use git pull to grab the new remote commit;


    to create a branch corresponding to the remote branch locally, use git checkout -b branch-name origin/branch- name, the name of the local and remote branches should be the same;


    to establish the association between the local branch and the remote branch, use git branch --set-upstream branch-name origin/branch-name;


    grab the branch from the remote, use git pull, if there is Conflicts must be dealt with first.




//tag
git tag tagname //New tag
git tag -a tagname -m "info" //Create a tag with description
git tag //View all tags
git tag tagname commitid //Specify commit id assignment tag
git show tagname // Check the tag description


git tag -s tagname -m "info" //Private key signature A tag
signature adopts PGP signature, therefore, gpg (GnuPG) must be installed first, if no gpg is found, or there is no gpg key pair, an error will be reported :
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
If an error is reported, please refer to the GnuPG help documentation to configure the Key.
PGP signature information can be seen with the command git show <tagname>:
tags signed with PGP are unforgeable because PGP signatures can be verified. The method of verifying the signature is more complicated and will not be introduced here.
git tag -d tagname //delete tag
git push origin tagname //push tag to remote
git push origin --tag //push all tags
//tag has been pushed, delete
git tag -d tagname //delete local git push origin : refs/tags/tagname //Delete remote


//Using github




    on GitHub, you can fork any open source repository;


    you have read and write permissions for the forked repository;


    you can push pull requests to the official repository to contribute code.
//Ignore special files




    When ignoring certain files, you need to write .gitignore;


    the .gitignore file itself needs to be placed in the repository, and .gitignore can be version managed!
//Configure git
to configure aliases for Git, so you can be lazy when entering commands. We encourage laziness.
Building Git server Linux system building, searching and learning to




    build a Git server is very simple, usually completed in 10 minutes;


    to facilitate the management of public keys, use Gitosis;


    To control permissions pervertedly like SVN, use Gitolite.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325816909&siteId=291194637