Skip to content

文章

Git 速查表

2014年10月1日 • 2 分钟阅读

Git 速查表

以下是我经常使用的 git 命令。

克隆仓库

git clone https://github.com/tinymce/tinymce-dist.git

将现有 git 文件添加到远程 git 仓库

cd /path/to/my/repo
git remote add origin https://lostinkali@bitbucket.org/lostinkali/flightstats.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

在现有文件夹中创建仓库

git init
git add .
# Adds the files in the local repository and stages them for commit
git commit -m "Initial commit"

将当前分支切换到 master

git checkout better_branch
git merge --strategy=ours master # keep the content of this branch, but record a merge
git checkout master
git merge better_branch

删除分支

git branch -D bugfix

恢复到之前的提交

git checkout master
git reset --hard e3f1e37
git push --force origin master
# Then to prove it (it won't print any diff)
git diff master..origin/master

将文件添加到 git。

git add [filename]

删除自最近一次提交以来的未跟踪文件。

git clean -fd

将添加的文件提交到 git。

git commit -m "enter message here"

从 git 中删除文件。使用 -f 强制删除文件,即使存在更改。

git rm file1.txt

标记特定的时间点。

git tag -a v1.4 -m 'my version 1.4'

作者:Chuck Conway 是一位 AI 工程师,拥有近 30 年的软件工程经验。他构建实用的 AI 系统——内容管道、基础设施代理和解决实际问题的工具——并分享他沿途的学习成果。在社交媒体上与他联系:X (@chuckconway) 或访问他的 YouTubeSubStack

↑ 返回顶部

你可能也喜欢