| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- .. eyefall post example, created by `ablog start` on Jan 25, 2021.
- Git in real world
- ===================
- .. post:: Jan 30, 2021
- :tags: git
- :category: programming
- Fetch tags from remote repository
- ----------------------------------
- .. code-block:: shell
- $git fetch --all --tags
- Checkout a tag as a branch
- ----------------------------
- .. code-block:: shell
- $git checkout tags/<tag_name> -b <new_branch_name>
- Ignore ^M as a newline when execute 'git diff'
- -----------------------------------------------
- .. code-block:: shell
- $git config --global core.autocrlf true
- 查看指定文件修改历史
- -------------------------
- .. code-block:: shell
- $git log --pretty=oneline [--oneline] <filename>
- 查看单次提交详情
- ----------------------------
- .. code-block:: shell
- $git show <commit>
- 撤销 git add
- ------------------------
- .. code-block:: shell
- $git reset HEAD
- $git reset HEAD <filename>
- $git reset HEAD <path>
- $git rm --cached <filename>
- 撤销 commit (没 push)
- -----------------------------
- .. code-block:: shell
- $git reset --soft HEAD^
- # 如果撤销 2 次 commit
- $git reset --soft HEAD~2
- # 其他参数
- --mixed 为默认参数,不删除工作空间代码改动,撤销 commit,并撤销 add
- # $git reset --mixed HEAD~2 == $git reset HEAD~2
- --soft 不删除工作空间代码改动,撤销 commit, 不撤销 add
- --hard 删除工作空间代码改动,撤销 commit,撤销 add
- rebase 远程分支
- ---------------------------
- 假设情景如下: 有一些本地分支,其中 master 是用来同步的主分支
- 对应自己有一个远程仓库 origin, origin 是 clone 自另一个仓库
- 假设地址在 https://github.com/a/b.git. 现在需要拉取原始仓库的更新
- .. code-block:: shell
-
- $git remote add upstream https://github.com/a/b.git
- $git fetch upstream
- $git checkout master
- $git rebase upstream/master
- $git push -f origin master
|