tips README

The project's README from github.com/git-tips/tips. As one markdown file: README.md.

git-tips

Collection of git-tips, want to add your tips? Checkout contributing.md

English | 中文 | Русский | 한국어 | Tiếng Việt | 日本語 | नेपाली | Polski | فارسی

Tools:

📖 Read the interactive GitBook documentation here!

P.S: All these commands are tested on git version 2.7.4 (Apple Git-66).

Table of Contents

Basic Operations

List of all files till a commit

git ls-tree --name-only -r <commit-ish>

Quickly switch to the previous branch

git checkout -

Alternatives:

git checkout @{-1}

Delete remote branch

git push origin --delete <remote_branchname>

Alternatives:

git push origin :<remote_branchname>
git branch -dr <remote/branch>

Delete remote tag

git push origin :refs/tags/<tag-name>

Undo local changes with the content in index(staging)

git checkout -- <file_name>

Alternatives:

git restore <file_name>

Reword the previous commit message

git commit -v --amend

See commit history for just the current branch

git cherry -v master

Amend author.

git commit --amend --author='Author Name <[email protected]>'

Stage parts of a changed file, instead of the entire file

git add -p

Pick commits across branches using cherry-pick

git checkout <branch-name> && git cherry-pick <commit-ish>

Grab a single file from a stash

git checkout <stash@{n}> -- <file_path>

Alternatives:

git checkout stash@{0} -- <file_path>

Create new working tree from a repository (git 2.5)

git worktree add -b <branch-name> <path> <start-point>

Create new working tree from HEAD state

git worktree add --detach <path> HEAD

Show all commits in the current branch yet to be merged to master

git cherry -v master

Alternatives:

git cherry -v master <branch-to-be-merged>

Modify previous commit without modifying the commit message

git add --all && git commit --amend --no-edit

Prunes references to remove branches that have been deleted in the remote.

git fetch -p

Alternatives:

git remote prune origin

Retrieve the commit hash of t

tips (git-tips/tips)

Searching Database…

21.7K ·GitHub
这是什么?一个由社区维护的 Git 常用技巧合集——都是针对日常 Git 任务、拿来即用的简短命令,并被翻译成了另外八种语言。
所以它是一份参考文档,不是一个要安装的软件?它是参考资料,不是软件:一份 README 速查表加一个交互式 GitBook。还有一个叫 'git-tip' 的配套命令行工具,可以在终端里浏览这些技巧,但仓库本身只是这份精选清单。
我平时怎么使用它?打开 README 或 GitBook,在目录里找到你的任务,复制需要的命令即可。如果想在终端里操作,可以用 'git-tip' 命令行工具,README 里演示了它在 Docker 容器中的运行方式。
这些命令在任何 git 版本上都能用吗?这些命令在 git 2.7.4 上测试过,清单里也收录了像 'switch' 和 'restore' 这类较新的现代替代写法——非常老的 git 版本可能缺少某些功能,比如 worktree。
我是 git 新手,应该从哪里入手?先看 Miscellaneous(杂项)部分的 'Everyday Git in twenty commands or so'——一份精简入门。然后把 Basic Operations 过一遍,再去研究 rebase 和历史操作这些进阶内容。
这份清单是怎么组织的?按任务分类:Basic Operations(基本操作)、Branching(分支)、Log and History(日志与历史)、Merging and Rebasing(合并与变基)、Stashing(贮藏)、Remotes(远程仓库)、Setup and Config(设置与配置)、Submodules and Subtrees(子模块与子树)、Tagging(标签)、Undoing Changes(撤销更改),还有一个 Miscellaneous(杂项)部分。
可以用其他语言阅读吗?可以——有中文、俄语、韩语、越南语、日语、尼泊尔语、波兰语和波斯语版本,链接在 README 顶部。
它能帮我解决什么样的麻烦?经典场景包括:已经推送之后从历史里删除敏感数据、找回被删除的文件、从 stash 里单独取出一个文件,或者用测试脚本自动执行 bisect,找出引入问题的那个提交。
它还在积极维护吗?在维护——README 由一个 Node 构建脚本从源文件生成,CI 工作流会自动重新构建并部署 GitBook 文档。这也是 GitHub 上仓库语言显示为 JavaScript 的原因:那是构建工具,不是内容本身。
Creator
git-tips
Size
1.2 MB
Stars
21.7K
Updated
CommitAug 10
Age
11y
Commits · 90 Days