Git init initializes the current directory as a repository that git can manage
git Add. #工作区文件add到暂存区
Git commit-m #暂存区文件提交到本地仓当前分支
git diff <file> #查看文件区别
git diff HEAD--<file> #查看工作区和版本库最新版本的区别
git log [--pretty=online] [--graph] #操作日志
git reset--hard head^ #回退到上一个版本
git reset--hard <commit id> #commit ID can not write full
git reset head <file> #把暂存区的修改撤销掉, re-put back into the workspace, when using HEAD, represents the latest version
Git reflog #显示操作记录
git checkout--[file] #丢弃工作区的修改
Command git checkout--readme.txt means to undo all changes to the Readme.txt file in the workspace, here are two things:
One is that Readme.txt has not been put into the staging area since the modification, and now, the undo changes back to the same state as the repository;
One is that the Readme.txt has been added to the staging area and modified, and now the undo changes go back to the state that was added to the staging area.
All in all, let this file go back to The state of the last git commit or git Add.
git rm <file> #从版本库删除文件
git remote add origin [email protected]:p Ath/repo-name.git #关联远程仓库
Git push-u Origin Master #第一次推送master分支的所有内容
Git push Origin master #将本地master分支的提交推送到远程库
Git push Origin dev #将本地的dev分支的所有提交推送到远程库的dev分支
git push #推送本地仓到远程仓
git clone <url> #从远程仓克隆
Git pull #从远程仓拉去更新到本地仓
Git status #仓库当前状态
Branch Branch Management
Git branch #查看分支
Git branch <name> #创建分支
git checkout <name> #切换到 <name> branches
git branch-d Dev #删除dev分支
git branch-d <name> #强行删除分支
Links to git branch--set-upstream dev origin/dev #指定本地dev分支与origin/dev Branch
git checkout-b dev #创建dev分支, then switch to Dev Branch,git checkout command plus the- b parameter means create and switch
git checkout-b dev Origin/dev #在本地创建和远程分支对应的分支dev
git merge dev #合并分支dev到当前分支
Stash Storage work site
Git stash #存储当前工作现场内容
git stash list #查看存储的工作现场
git stash apply [email protected]{0} #恢复存储的工作内容, do not delete stash
git stash drop [email protected]{0} #删除stash
git stash pop #恢复并删除stash
git remote #查看远程库信息
Git remote-v #更详细的远程库信息
Tag tag
git tag <name> #打标签
git Tag v1.0
git tag-a v0.1-m "xxxx" <commit id> #-A specify tag name,-m comment
git tag-s v0.2-m "xxxx" <commit id> #-s sign a label with the private key
git tag v0.9 6224937 #对应commit ID Tag
Git show <tagName> #查看标签信息
git tag #查看所有标签
git tag-d v0.1 #删除标签
Git push Origin v1.0 push tags to remote libraries (tags are created in remote libraries)
Git push Origin--tags #一次性推送全部尚未推送到远程的本地标签
To delete a tag that has been pushed to the remote:
git tag-d v0.9 #先本地删除
git push origin:refs/tags/v0.9 #从远程删除
Ignore file
In the GIT working directory file. Gitignore, add the ignored file names to the
Configure aliases
git config--global alias.st status #st表示status
git config--global alias.lg "log--color--graph--pretty=format: '%cred%h%creset-%c (yellow)%d%creset%s%cgreen (%CR)%c (bold blue) <%an>%creset '--abbrev-commit '
git config--global alias.last ' log-1 '
git config--global alias.unstage ' reset HEAD '
git config--global alias.co checkout
git config--global alias.ci commit
git config--global alias.br branch
Problem
After a local clone of GitHub above a name called Gitskills Repository, the local user home directory has a repository called Gitskills, then as previously said, I am local only Master branch, Even if the gitskills on GitHub has a master branch and a dev branch, I can only see the master branch in the repository of the local clone. My question is:
1. The push branch is the push of all local commits on the branch to the remote library. To specify a local branch when pushing, git pushes the "branch" to the remote branch of the remote library: Git push Origin master "does this branch" mean the current branch of the input pwd display?
2. The "$ Git push Origin master" is the default name for the remote repository, so what's the difference between it and the clone gitskills on GitHub? Is it an alias for Gitskills? Or all the other clonegithub. The repository above also has a unified alias: Origin?
3. "$ Git push Origin master" is the master in the local master branch or the clone repository branch?
4. "If you want to push other branches, such as Dev, change to:" Git push Origin dev "is this the same thing as pushing the local dev branch to the dev branch of the remote library? What if there is no dev branch in the remote library?
1, this branch refers to the branch in the phrase "$ GIT push origin local branch name"
2,origin is just the repository on the clone GitHub, equivalent to the current clone of the repository Gitskills alias is origin
3,$ git push origin master refers to the master in the local master, not the remote library in GitHub.
4, if you create a branch in the local repository Ceshi is associated with a branch ceshi_1 of the remote library origin in GitHub (assuming there are already ceshi_1 branches in the remote library) "$ git checkout-b ceshi origin/ceshi_1", So if you do it locally,
$ Git push origin ceshi--means to create a branch Ceshi on the remote Library (origin) on GitHub and push the contents of the local Ceshi branch to the new branch Ceshi on the remote Library (origin) instead of Pushed to the so-called ceshi_1 associated with it.
So if you want to push to the associated Ceshi_1, write the $ git push remote ceshi:ceshi_1
So when you create a local repository with a branch and a remote branch associated with it, the name is best.
Common commands for Git