Learn Git
====Git Skills==== --Sunic Yosen --Oct 28 2018 --Learn from: https:##www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 0.Git Environment 0) Install Git: sudo apt install git 1) Set user: git config --global user.name "Your Name" git config --global user.email "email@example.com" 1.Git usage git init ##Init repository git add <filename> ##Add file to git repository ##[把文件添加进去,实际上就是把文件修改添加到[暂存区]] git commit -m <message> ##Commit of this update and give comment with <-m> [提交&注释] ##[提交更改,实际上就是把暂存区的所有内容提交到当前分支] git status ##The status of repository git diff <filename> ##The changes detail of file <repository> ##Give the Version id HEAD ##Current version eg: git diff HEAD -- <filename> git diff --cached [比较的是暂存区的文件与仓库分支里(上次git commit 后的内容)的区别。] git log ## List the log/Journal of repository --pretty=oneline ## List one line of a log --graph ## See log with graphic -<count> ## List <count> logs git reset ##return to last version --hard HEAD ##Cuurent version HEAD^ ##Last version HEAD^^ ##Last second version HEAD~100 ##Last 100th version eg: git reset --hard HEAD^ ##Return last version <commit id> ##Return/Forward to <commit id> version ##Could Just Give the front of commit id git reflog ##Record all command, so you can call back.[会退到任意位置] git checkout -- <filename> ##Callback last version when not add modify to Repository ## -- is important. ##[尚未添加到暂存区,手动把文件恢复到上一个版本的状态,如果已经添加到Stage,那么回退到添加之后] ##['git checkout -- '其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”] ##If have added to stage, 'git reset HEAD <file>' could callback, and then 'git checkout --' ##If you have committed, 'git reset --hard <commit id> to return last version. git rm <filename> ##Remove file from repository. Then you should 'git commit -m <message>' to commit to repository git remote ## Check remote repository add origin <remote Address> ##Add remote repository named <origin> ##[关联一个远程库] -v ## check remote information git push ##Push to remote -u ##Used at the first time. ##Git will push local repository to remote, ##And it will make connect between local and remote. origin ##Remote repository name. master ##Remote branch name. <branch name> ##push to origin/<branch name> eg: git push -u origin master [First time] git push origin master git check ##Branch usage -b <branchname> ##Create and switch to a new branch <branchname> ##Switch to another branch git merge ##Merge Different branches. <branchname> ##Merge branch to master. --no-ff -m <message> <branchname> ## --no-ff ## [通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息。 ## 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以 ## 看出分支信息。] ## [合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并, ## 而fast forward合并就看不出来曾经做过合并。] ## [合并时没冲突且是ff模式,那就在log中不显示这个分支了] git branch ## control branches ##Check the branches. <branchname> ##Create Branch -d <branchname> ##Delete <branchname> --set-upstream-to=origin/<branchname> <branchname> git stash ##Cache what are doing but not committed list ## Check the stash list apply ## resume the WorkSpace <stashName> ## resume to special stash eg: git stash apply stash@{0} drop ## delete after apply pop ## resume and delete git pull ##fetch remote branch ## git rebase ##rebase git log ## git tag ##tag the version ##Check tag the branch version <tagName> ##Tag as <tagName> <tagName> <commitID> ##Tag <commitID> as <tagName> -a <signature> ##signature -m <comment> ##comment -d <tagName> ##Delete <tagName> git push origin <tagName> ##push <tagName> to remote git push origin --tags ##push all tags to remote git push origin :refs/tags/<tagName> ##delete tags from remote ##You should delete <tagName> at local first git show <tagName> ## Show info of <tagName> git config ##git config at $HOME/.gitconfig --global ##global setting color.ui [true/false] ##git color theme user.name=<name> ## user.email=<email> ## alias.<name1> <name2> ##alias name2 -> name1 git check-ignore -v <fileName> ## Check <fileName> ignore git add -f <fileName> ## If ignore by .gitignore add force github fork Can remote <Other' Repository> and <My Repository> in github, May be: <Other' Repository> ---> git remote add origin git@github.com:xxxx/xxx.git <My Repository> ---> git remote add develop git@github.com:sunyongshuai/xxxx.git <git remote -v > will get two remote repositories.
Git Clone Speed:
1. 编辑 hosts文件: sudo vim /etc/hosts
添加映射
151.101.73.194 github.global.ssl.fastly.net
192.30.253.112 github.com
2. 刷新DNS: sudo killall -HUP mDNSResponder
3. 查找适合自己的映射ip地址: http://ping.chinaz.com http://ipaddress.com
Welcome to my github: https://github.com/SunYongshuai/LearnGit