Git summary

 

 

git command

git init

Create an empty git repository

 

git add <file>

Save the file to the staging area

 

git commit -m "..."

Commit the contents of the staging area to the branch

 

git diff <file>

Compare file differences

 

git status

View current status

 

git log

View History

 

git reflog

View the history to determine which version back to the future

 

git reset --hard <commit_id>

HEAD means the current version, the previous version is HEAD^, the previous version is HEAD^^, and the previous 100 versions are HEAD~100

 

git checkout -- <file>

Revoke the modified file back to the previous state. If it has been submitted to the staging area and then modified, it will be restored to the content when it was submitted to the staging area. Note -- very important, if not -- switch to a certain branched

 

git rm <file>

Delete a file, if you want to restore git reset <commit_id>, then git checkout -- <file>

 

git associate remote repository

git remote add origin git@server-name:path/repo-name.git

git push -u origin master #First push

git push origin master

 

 

View branch

git branch       

 

create branch

git branch <name>

 

switch branch

git checkout <name>

 

Merge a branch into the current branch

git merge <name>

If it is currently under the master branch, git merge dev is to merge dev into master

git merge --no-ff -m "merge with no-ff" dev disable fast-forward mode 

 

delete branch

git branch -d <name>

git breanch -D <name>   强制删除

 

把现场的工作先保存

git stash

git stash list

git stash apply   可以恢复多次

git stash pop      只能恢复一次

 

查看远程库信息

git remote -v

 

从本地推送分支

git push origin branch-name

 

从远程抓取分支

git pull origin branch-name

 

 

 

用于新建一个标签,默认为HEAD,也可以指定一个commit id

git tag <name> <commit_id>

 

可以指定标签信息

git tag -a <tagname> -m "..."

 

可以用PGP签名标签

git tag -s <tagname> -m "b..."

 

查看所有标签

git tag 

 

可以推送一个本地标签

git push origin <tagname>

 

可以推送全部未推送过的本地标签

git push origin --tags

 

删除一个本地标签

git tag -d <tagname>

 

删除一个远程标签

git push origin :refs/tags/<tagname>

 

 

 

参考

探索git目录

git教程

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326574131&siteId=291194637