What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
software_dev:ver_ctrl:git [2023/12/13 01:45] – [git stash] codingharesoftware_dev:ver_ctrl:git [2023/12/15 00:53] (当前版本) – [Tagging] codinghare
行 207: 行 207:
 </code> </code>
 这一段代表了当前 ''master'' 与 ''branch'' 开始时的 ''master'' 中的内容差异。我们可以选择保留当前的 ''master'' 的修改,或是保留 ''branch'' 中对应的 ''master'' 内容。但无论如何,除了要保留的内容以外,其他所有内容(包括 git 自动产生的标记)都需要删除。 这一段代表了当前 ''master'' 与 ''branch'' 开始时的 ''master'' 中的内容差异。我们可以选择保留当前的 ''master'' 的修改,或是保留 ''branch'' 中对应的 ''master'' 内容。但无论如何,除了要保留的内容以外,其他所有内容(包括 git 自动产生的标记)都需要删除。
 +===Tagging===
 +git 中可以对指定的分支做 tag:
 +<code bash>
 +# switch to the branch before tagging
 +git tag <tag_name>
 +
 +# listing exsiting tag
 +git tag
 +
 +#deleting tag
 +git tag -d <tag_name>
 +
 +#deleting tag on origin
 +git tag -d <tag_name>
 +git push origin :refs/tags/<tagname>
 +</code>
 +默认的 tag 是关联到当前分支的**最新** commit 上的。如果希望对指定的 commit 打 tag (比如忘记打了),需要加上 commit id:
 +<code bash>
 +git tag <tag_name> <commit id / 7 digits>
 +
 +# creating tag with extra message
 +git tag <tag_name> -m "your message here" <commit id>
 +
 +</code>
 +打好 tag 以后就可以很方便根据 tag 查看 commit 了:
 +<code bash>
 +git show <tag_name>
 +</code>
 +tag 默认存在本地。如果要推送到远程,使用以下命令:
 +<code bash>
 +git push origin <tag_name>
 +
 +#push all tags at once
 +git push origin --tags
 +</code>
 ===Teamwork=== ===Teamwork===
 在多人使用 git 进行合作中,一般会需要: 在多人使用 git 进行合作中,一般会需要:
行 236: 行 271:
 #push your branch feature to the remote #push your branch feature to the remote
 git push origin your_branch_name git push origin your_branch_name
 +
 +#fetch and merge the newest master
 +git pull origin master
 +</code>
 +==git rebase==
 +我们在 push 的时候,如果 origin 对应分支已经发生了改变(别人提交过了),那么需要用 fetch/merge 或是 pull 来同步 origin 中的新内容到本地分支。但这样做的问题在于,我们在本地的 commits 实际上处于 pull commit 之后了,那么从路径上来说我们的 commit 之于 master 的新内容之前。这样顺序是不对的。
 +\\ \\
 +''git rebase'' 会将本地 commit 的提交历史止于 pull(origin 内容更新之后),等于重新顺理了一遍提交顺序。这样看使提交历史起来更加直观。
 +<code bash>
 +# before
 +|\
 +| * d662d56 (origin/master) Update readme.md.txt
 +* | 30bcffe modified hello2.py
 +* | 9091cc7 add hello2.py
 +|/
 +
 +# after git rebase
 +
 +* 280680e (HEAD -> master) modified hello2.py
 +* 8337019 add hello2.py
 +* d662d56 (origin/master) Update readme.md.txt
 +
 +#after push
 +* 280680e (HEAD -> master, origin/master) modified hello2.py
 +* 8337019 add hello2.py
 +* d662d56 Update readme.md.txt
 </code> </code>
 ==git clone== ==git clone==
行 259: 行 320:
 # -u: push the new data and link the local branch to the cloud branch # -u: push the new data and link the local branch to the cloud branch
 git push -u origin master git push -u origin master
 +</code>
 +===Tips===
 +==误回滚回复==
 +如果知道想回滚版本的 hash:
 +<code bash>
 +git reset --hard hash
 +</code>
 +如果不知道:
 +<code bash>
 +#find the hash
 +git reflog
 +#backtrack
 +git reset --hard hash
 +</code>
 +==将 master 上修复的 bug 同步合并到 dev 上==
 +这种情况一般出现在:
 +  * 你正在开发新的东西
 +  * 当前的 master 分支出现了 Bug 并被修复了
 +这种情况下,无需去 dev 分支上再把 bug 修改一遍,只需在 dev 分支上使用如下命令即可合并 Bug 修复内容到 dev:
 +<code bash>
 +git cherry-pick <bug-fix-commit-code-7-digits>
 </code> </code>
 ====Git Hub==== ====Git Hub====
行 345: 行 427:
 git config core.filemode false git config core.filemode false
 </code> </code>
-==误回滚回复== +
-如果知道想回滚版本的 hash: +
-<code bash> +
-git reset --hard hash +
-</code> +
-如果不知道: +
-<code bash> +
-#find the hash +
-git reflog +
-#backtrack +
-git reset --hard hash +
-</code>+
 ====References==== ====References====
   * [[https://education.github.com/git-cheat-sheet-education.pdf|cheatsheet]]   * [[https://education.github.com/git-cheat-sheet-education.pdf|cheatsheet]]
   * [[https://www.liaoxuefeng.com/wiki/896043488029600/900005860592480|廖雪峰的官方网站]]   * [[https://www.liaoxuefeng.com/wiki/896043488029600/900005860592480|廖雪峰的官方网站]]