贡献者 Git 命令指南
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
虽然我们都熟悉源代码管理,但使用 fork 仓库并确保顺畅合并会带来额外挑战。本文旨在帮助你处理那些可能需要操作但可能不太熟悉的场景。
放轻松,准备好你的毛巾(别慌)。
如果你不习惯使用命令行操作 Git,我们推荐 GitKraken。这是最好的跨平台 Git 工具,我们在下方也添加了相关使用说明。
未遵守常规提交规范
- GitKraken
- CLI
Open your oh-my-posh repo inside GitKraken and right click the commit you want to reword in the graph overview.
Select Edit commit message, reword it to respect the conventional commit guidelines and press Update message.
Click Push on the top of the screen and select Force Push to bring the changes to the Pull Request.
I only have 1 commit
To reword the last commit, we can make use of git's --amend switch to add something to our latest commit (code, changes, rewording).
Use the following commands to rephrase the last commit and get that change merged!
git commit --amend -m "feat: better worded feature"`
git push --force
I added more than commit
If all of your commits need to go to main because it makes sense to treat these as atomic units, you can use git's interactive rebase
functionality to reword any commit between main and your HEAD. To start an interactive rebase, type git rebase -i main.
This will open your $EDITOR and you can mark the commits you want to reword with reword (or r) rather than pick.
Exiting that file will start the rebase and spawn your $EDITOR to alter the commit message for each commit you marked as reword.
Once done, use git push --force to bring the changes to the pull request.
The latest version of vscode has a built-in gui to help you select reword or any other action on a commit. Select the right ones and press
Start Rebase to continue.
我的分支与远程不同步
这意味着 oh-my-posh 的主分支包含你的分支没有的提交(可能是你的主分支或工作分支)。为了解决这个问题,我们需要执行变基操作(将 oh-my-posh 主分支的新提交放在你的新提交下方),这样拉取请求才能成功合并。
首先需要将 oh-my-posh 代码库添加为本地 Git 仓库的远程源。默认情况下,你的 fork 仓库是 oh-my-posh 的独立副本,在 GitHub 上有自己的远程源,与 oh-my-posh 原始代码库没有连接。Fork 和 Pull Request 是 GitHub 在 Git 功能基础上引入的特性,因此我们需要手动模拟这种情况。
添加远程源到本地 Git 仓库
- GitKraken
- CLI
Hover over Remote on the left-hand side, this will show a + button. Click it and select GitHub. There you have the ability to select
jandedobbeleer/oh-my-posh and name it upstream. GitKraken will fetch the remote and you will see all branches underneath upstream as
you do for your own branches. Right click upstream's main branch and select Rebase <branch> onto upstream/main.
Click Push on the top of the screen and select Force Push to bring the changes to the Pull Request.
git remote add upstream git@github.com:JanDeDobbeleer/oh-my-posh.git
git fetch upstream
将分支变基到上游主分支
- GitKraken
- CLI
Right click upstream's main branch and select Rebase <branch> onto upstream/main. Click Push on the top of the screen and select
Force Push to bring the changes to the Pull Request.
git rebase upstream/main
git push --force