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 # 首次推送仓库及其引用
git push -u origin --tags # 推送所有标签

在现有文件夹中创建仓库

git init
git add .
# 将本地仓库中的文件添加并暂存以供提交
git commit -m "Initial commit"

将当前分支更改为 master

git checkout better_branch
git merge --strategy=ours master # 保留此分支的内容,但记录合并
git checkout master
git merge better_branch

删除分支

git branch -D bugfix

回退到之前的提交

git checkout master
git reset --hard e3f1e37
git push --force origin master
# 然后验证它(不会打印任何差异)
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 专注于软件工程和生成式人工智能。在社交媒体上与他联系:X (@chuckconway) 或访问他的 YouTube

↑ 回到顶部

您可能还喜欢