0


GIT常用命令

文章目录


前言

当前工作区 —add—> stage —commit—> 本地仓库 —push—> 远程仓库
pull   push
branch
rebase
merge
reset   revert
checkout


一、必备命令

push之前先pull一下

git push  # 默认情况下仅将当前分支推送到远程对应的分支# 若hard会退过 git reset --hard HEAD^ 则需要强制push,用下面的命令git push origin <对应的BranchName>--forcegit push --all# 将所有分支推送到远程

rebase 变基

a——b——c(master)||__d——e——f(*subbranch)git rebase master

will be:
a——b——c(master)——d‘——e’——f‘(*subbranch)
有点像
将d合并到master生成d',再将e合并到d'生成e',再将f合并到e'生成f'
删去def将(*subbranch)变更到f‘

merge

a——b (*master)||_c (我需要被合并)git merge 把谁合并过来

a——b——d(*master)|     ↑
|____ c (我需要被合并)

branch

强制修改分支位置

git branch -f master HEAD~3

reset

永久回退

git reset --hard HEAD^

revert

前进一个负直

git revert HEAD^

二、将本地项目推送到远程

远程仓库有文件

//初始化
git init
//关联远程仓库
git remote add origin 远程地址
//拉取远程master分支上内容
git fetch origin master
//设置当前分支为远程仓库的master分支
git branch --set-upstream-to=origin/master master
//提交本地文件到暂存区
gitadd.
//将暂存区内容添加到本地仓库中
git commit -m"注释"
//推送到远程分支
git push

远程仓库无文件

//初始化
git init
//从现有 Git 仓库中拷贝项目
git clone
//关联远程仓库
git remote add origin 远程地址
//提交本地文件到暂存区
gitadd.
//将暂存区内容添加到本地仓库中
git commit -m"注释"
//推送到远程分支
git push

总结

#mermaid-svg-Zigx6lplzd3Dfx8h {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .error-icon{fill:#552222;}#mermaid-svg-Zigx6lplzd3Dfx8h .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Zigx6lplzd3Dfx8h .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-Zigx6lplzd3Dfx8h .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Zigx6lplzd3Dfx8h .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Zigx6lplzd3Dfx8h .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Zigx6lplzd3Dfx8h .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Zigx6lplzd3Dfx8h .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Zigx6lplzd3Dfx8h .marker.cross{stroke:#333333;}#mermaid-svg-Zigx6lplzd3Dfx8h svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Zigx6lplzd3Dfx8h .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .cluster-label text{fill:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .cluster-label span{color:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .label text,#mermaid-svg-Zigx6lplzd3Dfx8h span{fill:#333;color:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .node rect,#mermaid-svg-Zigx6lplzd3Dfx8h .node circle,#mermaid-svg-Zigx6lplzd3Dfx8h .node ellipse,#mermaid-svg-Zigx6lplzd3Dfx8h .node polygon,#mermaid-svg-Zigx6lplzd3Dfx8h .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Zigx6lplzd3Dfx8h .node .label{text-align:center;}#mermaid-svg-Zigx6lplzd3Dfx8h .node.clickable{cursor:pointer;}#mermaid-svg-Zigx6lplzd3Dfx8h .arrowheadPath{fill:#333333;}#mermaid-svg-Zigx6lplzd3Dfx8h .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Zigx6lplzd3Dfx8h .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Zigx6lplzd3Dfx8h .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-Zigx6lplzd3Dfx8h .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-Zigx6lplzd3Dfx8h .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Zigx6lplzd3Dfx8h .cluster text{fill:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h .cluster span{color:#333;}#mermaid-svg-Zigx6lplzd3Dfx8h div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Zigx6lplzd3Dfx8h :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
add

commit

push

push

unstage

       working 
     

       stage 
     

       local_repo 
     

       remote 
     

问题

  1. 空文件夹问题 git追踪内容而不是目录,所有git会忽略空目录。 解决方法:在空目录下新建一个空文件,如.gitkeep
  2. 让git忽略某些文件/文件夹 新建.gitignore文件,将要忽略的文件夹或文件直接添加进去即可

references

csdn blog 关于Git这一篇就够了

标签: git

本文转载自: https://blog.csdn.net/surfaceyan/article/details/128057682
版权归原作者 耶耶耶耶耶~ 所有, 如有侵权,请联系我们删除。

“GIT常用命令”的评论:

还没有评论