Git教程-分支和tag管理

2023-05-16

转自:Ricky_Fung(http://blog.csdn.net/top_code/article/details/52336221


1、列出所有本地分支


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git branch</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

2、列出所有远程分支


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git branch -r</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

3、列出所有本地分支和远程分支


<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git branch <span class="hljs-operator" style="box-sizing: border-box;">-a</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

4、新建一个分支,但依然停留在当前分支


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git branch [branch-name]</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,创建名称为dev的分支:


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git branch dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

5、新建一个分支,并切换到该分支


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git checkout -b [branch]</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,创建名称为dev的分支并切换到该分支上


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git checkout -b dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

6、切换到指定分支,并更新工作区


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git checkout [branch-name]</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,切换到dev分支上


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git checkout dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

7、合并指定分支到当前分支


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git merge [branch]</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,当前在master分支上,将dev分支合并到当前master分支上来


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git merge dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

8、删除分支


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git branch <span class="hljs-attribute" style="box-sizing: border-box;">-d</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span>branch<span class="hljs-attribute" style="box-sizing: border-box;">-name</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,删除本地dev分支


<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git branch <span class="hljs-operator" style="box-sizing: border-box;">-d</span> dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

9、将本地分支推送到远程服务器

10、删除远程分支


<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">push</span> origin --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> <branchName></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,删除远程的dev分支


<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">push</span> origin --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

否则,可以使用这种语法,推送一个空分支到远程分支,其实就相当于删除远程分支:


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git branch -d <branchName>
<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git push origin <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:<branchName></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>  

标签(tag)操作

1、列出所有tag


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git tag</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

2、打轻量标签


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> name<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

3、附注标签


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-attribute" style="box-sizing: border-box;">-a</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> name<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"> -m </span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span>message<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,打v1.0标签


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-attribute" style="box-sizing: border-box;">-a</span> v1<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> <span class="hljs-attribute" style="box-sizing: border-box;">-m</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'v1.0 release'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

4、后期打标签


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-attribute" style="box-sizing: border-box;">-a</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> name<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"> </span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span>version<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

5、删除本地tag


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-attribute" style="box-sizing: border-box;">-d</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">[</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">]</span><span class="hljs-markup" style="box-sizing: border-box;"></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,删除本地v1.0 标签


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">tag</span> <span class="hljs-attribute" style="box-sizing: border-box;">-d</span> v1<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

6、删除远程tag


<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">push</span> origin --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> tag <tagname></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

还有另外一种方式来删除,推送一个空tag到远程


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git tag -d <tagname>
<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git push origin <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:refs/tags/<tagname></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>  

7、 查看tag信息


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git show [tag]</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

9、提交指定tag


<code class="hljs css has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">git</span> <span class="hljs-tag" style="color: rgb(0, 0, 0); box-sizing: border-box;">push</span> <span class="hljs-attr_selector" style="color: rgb(0, 136, 0); box-sizing: border-box;">[remote]</span> <span class="hljs-attr_selector" style="color: rgb(0, 136, 0); box-sizing: border-box;">[tag]</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

例如,将v1.0标签推送到远程服务器上


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git push origin v1.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

10、提交所有tag


<code class="hljs brainfuck has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">$</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">git</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">push</span> <span class="hljs-title" style="box-sizing: border-box;">[</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">remote</span><span class="hljs-title" style="box-sizing: border-box;">]</span> <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">-</span><span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">-</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">tags</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

重命名远程分支

在git中重命名远程分支,其实就是先删除远程分支,然后重命名本地分支,再重新提交一个远程分支。

例如,把远程分支dev重命名为develop,操作如下:

1.删除远程分支:


<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ git <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">push</span> --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">delete</span> origin dev</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

2.重命名本地分支:


<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">git branch <span class="hljs-attribute" style="box-sizing: border-box;">-m</span> dev develop</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>  

3.推送本地分支:


<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>git push origin develop</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">
</li></ul>  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Git教程-分支和tag管理 的相关文章

  • 将新文件推送到新存储库 Git

    我是 git 新手 还没有完全了解工作流程 因此 我在 github com 上创建了一个存储库 并且能够从我的计算机推送所有文件 现在我已经在 github 上创建了一个新的存储库 并在我的计算机上创建了一个新文件夹 所有内容都从新文件夹
  • 将两个相似的远程 git 存储库合并为一个

    我已经做了一些搜索并阅读了 git 书籍和网络上的一些地方 例如 git 但我找不到正确的方法来做到这一点 我有两个 git 存储库 位于两台不同的机器上 这些 git 存储库中的每一个都保存程序的配置 当您比较两个存储库时 配置的某些部分
  • 只在一个文件上应用 git merge stategy 吗?

    当将一个分支合并到另一个分支时 可以定义合并策略 例如 git merge release X ours 当将发布分支中的内容合并到当前分支时 这会在全局范围内应用 我们的 策略 是否可以仅对一个特定文件应用此策略 例如 git merge
  • 即使在签出到另一个分支后也无法删除本地分支

    我正在尝试删除我的本地分支并尝试了我在这里找到的大多数解决方案 即签出到另一个分支然后运行git branch D or d
  • 当必须同时使用 Git 和 Subversion 时如何处理 Git-svn

    Update 更详细地说 我尝试在家使用纯 Git 的原因是 我的公司希望迁移到 Git 但经理不愿意进行更改 因为开发人员不了解我们自己的存储库上的 Git 所以 我尝试做的是 我尝试让每个人都使用 Pure git 同时有人可以在这个学
  • 我可以用一个命令销毁并重新创建 Git 远程分支吗?

    在 Git 中 我有时会在长期运行的分支上工作 我喜欢时不时地重新建立 master 基础 以便在准备好时使合并变得更容易 变基后 我无法将先前推送的分支推送到远程 因为我的分支的历史记录不再与该分支的远程历史记录一致 所以我必须先删除它
  • 让“git pull”在拉取不同分支时要求确认

    当同时处理许多项目和分支时 我偶尔会犯一些愚蠢的错误 比如拉入错误的分支 例如在分支上master I did git pull origin dangerous code并且有一段时间没有注意到这一点 这个小错误造成了很大的混乱 当我尝试
  • Jenkins 多分支管道 - 在分支中配置属性?

    我们已经使用 Jenkins 多分支管道插件成功设置了构建管道 该插件在大多数情况下都运行良好 但是我们遇到了一个困扰我们的问题 Jenkinsfile包含一组属性 这些属性也显示在 UI 中 但如何为各个分支设置默认值 这就是我们的属性定
  • Git 二进制文件与 .gitattributes 中的 -diff

    在 gitattributes 中有以下等价内容 chm binary chm diff 我努力了 chm二进制文件 但恐怕它仍然可能尝试合并这些文件 是 diff更适合我打算做什么 另外 在提交给定类型的文件后 此设置是否适用 Thank
  • 在 github 上查找强制推送的提交者

    在我们的项目 托管在 GitHub 上 中 每隔一段时间就会有人意外强制推送 master 没有人知道是否这样做 我想找出是谁干的 以及背后有什么样的错误配置的工具或坏习惯 那么问题来了 如何识别进行强制推送的用户呢 当我拉动时 我看到这样
  • 克隆存储库时出现 Git 冲突复制错误

    我使用 dropbox 作为 git 存储库 现在由于同步中的一些问题 git 中存在一些冲突的副本 我该如何消除这种冲突 由于这种冲突 我无法克隆该存储库的内容 我在克隆存储库时遇到的错误是 Git 致命 参考格式无效 refs head
  • 为什么每次合并分支后我的 git log graph 都会多增长一行?

    我习惯使用git log oneline graph decorate all作为别名git ll在终端中查看提交图表 但是当我每次合并我的时 一个问题让我感到困惑develop to master 上面命令的输出可能是这样的 0d1bf7
  • 如何在gitlab存储库中下载单个文件夹或文件

    我有一个存储库 在此存储库中 有多个文件夹可用 我只需要此存储库中的一个文件夹 我已经尝试遵循命令 但它不起作用 克隆 有没有办法只克隆 git 存储库子目录 https stackoverflow com questions 600079
  • 无法使用 File delete() 方法删除 git repo 中的 .pack 文件

    对于我正在编写的这个方法 我使用 jgit 库克隆一个 git 存储库 然后对这些文件执行一些操作 最后我想删除该存储库 我遇到的问题是 当我在 pack 文件 位于 git objects pack 中 上调用 delete 方法时 它无
  • 运行“git gui”时如何跳过“松散对象”弹出窗口

    当我运行 git gui 时 我会看到一个弹出窗口 上面写着 This repository currently has approximately 1500 loose objects 然后它建议压缩数据库 我之前已经这样做过 它将松散对
  • 在 VS Code 中找不到 Git

    由于某种原因 我在 Windows 10 笔记本电脑上运行的 VS Code 中找不到 Git 在我的 Mac 上 当你一直向下滚动时 用户默认设置 中会出现一个 Git 但在我的 Windows 10 笔记本电脑上 它根本不存在 源代码管
  • 如何在保留历史记录的同时将 git 存储库重新设置为父文件夹?

    我有一个 git 仓库 foo bar baz具有大量的提交历史和多个分支 我现在想要 foo qux位于同一个仓库中 foo bar baz 这意味着我需要它们都位于植根于的存储库中 foo 但是 我想保留我所做的更改的历史记录 foo
  • 在 PowerShell 错误消息中使用 touch 命令创建新文件

    我的桌面上有一个使用 PowerShell 创建的目录 现在我尝试在其中创建一个文本文件 我确实将目录更改为新目录 然后输入touch textfile txt 这是我收到的错误消息 touch The term touch is not
  • 如何忽略Git中以数字开头的文件?

    在某个文件夹中 我有名为foo jpg bar png等等 我想将它们保留在版本控制中 除了那些命名为1 baz png 2 zaz jpg等 因为它们实际上是生成的 我应该添加什么条目 gitignore 正则表达式如 0 9 似乎不起作
  • git stash 和编辑帅哥

    我完全喜欢git add p and git stash但我偶尔会遇到以下问题 该问题是通过以下命令序列重现的 git add p my file 然后我手动编辑大块 using e 因为 git 建议的分割不适合我 git stash k

随机推荐

  • Install OpenCV+ Python in Ubuntu

    1 VMware安装ubuntu 不建议在Windows下学习 安装教程 Tip1 xff1a Ubuntu安装结束后无法正常联网 然后就是等待漫长的更新 Tip2 文件含有中文名 打开终端 export LANG 61 en US xdg
  • Tracking motion in video

    Tracking motion in video Download the source code to Ball Tracking with OpenCV
  • parse command line arguments

    parse command line arguments
  • 计算机网络

    计算机网络 一 计算机网络体系结构 二 物理层 三 数据链路层 四 网络层 五 运输层 六 应用层
  • 【c++初学】遇到问题:对xxx未定义的引用

    在编译的时候遇到了 未定义引用 root 64 czp span class token operator span PC span class token operator span span class token operator s
  • 在同一个浏览器上打开同一个网址只打开一个窗口的方法

    具体问题看图吧 xff0c 我自己也说不清楚 具体操作如下 xff1a target属性的功能之一是可以在同一个浏览器中只打开被标记相同的网页窗口 利用这一功能可以实现以上问题 target属性链接地址 xff1a http www w3s
  • esp32 Arduino IDE读取航模接收机SBUS信号

    库函数下载链接https download csdn net download qq 40925542 87207281 该库函数适用于具有多个串口的开发板 xff0c esp32中测试通过 xff0c 测试代码如下 xff1a inclu
  • curl 401 unauthorized解决

    用curl获取web信息时遇到了401unauthorized错误 用下面的命令解决了 xff1a span class token function curl span insecure anyauth u admin password
  • git自建服务器-借助蒲公英实现远程访问

    git自建服务器 借助蒲公英实现远程访问 本文涉及蒲公英组网 xff0c 这里大家可以参考蒲公英官网组网教程 使用的硬件 蒲公英x3a 路由器 xff1a 用于智能组网 xff0c 实现内网穿透vpn功能 xff1b orange pi3
  • sockaddr与sockaddr_in结构体简介

    span class token keyword struct span sockaddr span class token punctuation span span class token keyword unsigned span s
  • ROS入门(二)——创建功能包和工作空间

    提示 xff1a 文章写完后 xff0c 目录可以自动生成 xff0c 如何生成可参考右边的帮助文档 文章目录 前言一 工作空间 xff08 workspace xff09 xff1f 二 创建工作空间 xff08 workspace xf
  • SpringBoot异常处理-SimpleMappingExceptionResolver(四)

    异常处理 SimpleMappingExceptionResolver 配置 SimpleMappingExceptionResolver 处理异常 在全局异常类中添加一个方法完成异常的同一处理 结果是只不返回参数 没有上一个博客方法好 但
  • Matplotlib三维绘图,这一篇就够了

    Matplotlib三维绘图 xff0c 这一篇就够了 1 效果图1 1 3D线效果图1 2 3D散点效果图1 3 3D随机颜色散点效果图1 4 3D散点不同mark点效果图1 5 3D线框效果图1 6 3D曲面不透明效果图1 7 3D曲面
  • C++编程永不过时的语言,原因何在?

    想要知道C 43 43 到底如何你首先要了解C 43 43 的特性 C 43 43 既保留了C语言的有效性 灵活性 便于移植等全部精华和特点 xff0c 又添加了面向对象编程的支持 xff0c 具有强大的编程功能 xff0c 可方便地构造出
  • px4ctrl代码解读-px4ctrl_node

    头文件 include lt ros ros h gt include 34 PX4CtrlFSM h 34 include lt signal h gt 1 初始化节点 ros init argc argv 34 px4ctrl 34 r
  • ZYNQ图像处理(1)——vdma_hdmi显示环境搭建

    1 引言 FPGA是一种现场可编程逻辑门阵列 xff0c 其并行的特点让其在图像处理 数字通信等领域有广泛的应用 FPGA缺点是不擅长流程控制 xff0c 对于IIC SPI等通信方式 xff0c 往往需要用到状态机 ZYNQ7000是赛灵
  • 大小端知识

    大端和小端 xff08 Big Endian和Little Endian xff09 xff1a 1 Little Endian就是低位字节排放在内存的低地址端 xff0c 高位字节排放在内存的高地址端 2 Big Endian就是高位字节
  • rplidarA3 QT调试记录

    使用软件和环境 xff1a rplidar A3 win10 32位 QT5 13 msvc2017 32位 先下载rplidar官方sdk xff0c http www slamtec com cn Support rplidar a s
  • cmake相关:sudo make install后的卸载

    sudo make install后的卸载 我们知道linux中一般的编译一个package的顺序是 span class token function git span clone package git span class token
  • Git教程-分支和tag管理

    转自 xff1a Ricky Fung xff08 http blog csdn net top code article details 52336221 xff09 1 列出所有本地分支 lt code class 61 34 hljs