$ git rebase --onto SHA1_OF_BAD_COMMIT^ SHA1_OF_BAD_COMMIT $ git push -f [remote] [branch] 或者做一个 交互式rebase 删除那些你想要删除的提交(commit)里所对应的行。 我尝试推一个修正后的提交(amended commit)到远程,但是报错: To https://github.com/yourusername/repo.git ! [rejected] my...
注意, rebasing(见下面)和修正(amending)会用一个新的提交(commit)代替旧的, 所以如果之前你已经往远程仓库上推过一次修正前的提交(commit),那你现在就必须强推(force push) (-f)。注意 –总是确保你指明一个分支! (my-branch)$ git push origin mybranch -f 一般来说,要避免强推. 最好是创建和推(push)...
暂存(Staging)我需要把暂存的内容添加到上一次的提交(commit)(my-branch*)$ git commit --amend 我想要暂存一个新文件的一部分,而不是这个文件的全部 一般来说, 如果你想暂存一个文件的一部分, 你可这样做: $ git add --patch filename.x -p 简写。这会打开交互模式, 你将能够用 s 选项来分隔提交(com...
注意, rebasing(见下面)和修正 (amending) 会用一个新的提交 (commit) 代替旧的, 所以如果之前你已经往远程仓库上推过一次修正前的提交 (commit),那你现在就必须强推 (force push) (-f)。注意 – 总是 确保你指明一个分支! (my-branch)$ git push origin mybranch -f 一般来说,要避免强推. 最好是创...
This option is useful in the case where one is developing a feature on top of an upstream branch. While the feature is being worked on, the upstream branch may advance and it may not be the best idea to keep rebasing on top of the upstream but to keep the base commit as-is. As th...
git reset HEAD^ --hard git push -f [remote] [branch] 如果你还没有推到远程, 把Git重置(reset)到你最后一次提交前的状态就可以了(同时保存暂存的变化): (my-branch*)git reset --soft HEAD@{1} 这只能在没有推送之前有用. 如果你已经推了, 唯一安全能做的是git revert SHAofBadCommit, 那会创建...
On branch main No commits yet nothing to commit (create/copy files and use "git add" to track) 使用ls 命令以显示工作树的内容: Bash 复制 ls -a 确认目录包含一个名为“.git”的子目录。 (将 -a 选项与 ls 结合使用非常重要,因为 Linux 通常会隐藏以句点开头的文件和目录名称。)此文件夹为...
git checkout -b <branchname> Let's have a look at a visual example. Three changes have been committed to the Git system on the main branch. The main branch is the currently selected branch because the HEAD pointer is referencing the main branch. With every commit, the main branch points...
(my-branch*)$ gitreset--softHEAD@{1} 1. 这只能在没有推送之前有用. 如果你已经推了, 唯一安全能做的是 git revert SHAofBadCommit, 那会创建一个新的提交(commit)用于撤消前一个提交的所有变化(changes);或者, 如果你推的这个分支是rebase-safe的 (例如:其它开发者不会从这个分支拉), 只需要使用 gi...
(my-branch*)$ git reset --soft HEAD@{1} 这只能在没有推送之前有用. 如果你已经推了, 唯一安全能做的是git revert SHAofBadCommit, 那会创建一个新的提交(commit)用于撤消前一个提交的所有变化(changes);或者, 如果你推的这个分支是rebase-safe的 (例如:其它开发者不会从这个分支拉), 只需要使用git ...