如何修改特定提交?

发布于 2024-07-29 03:05:06 字数 246 浏览 7 评论 0 原文

我有以下提交历史记录:

  1. HEAD
  2. HEAD~
  3. HEAD~2
  4. HEAD~3

git commit - -amend 修改当前的 HEAD 提交。 但如何修改 HEAD~3 呢?

I have the following commit history:

  1. HEAD
  2. HEAD~
  3. HEAD~2
  4. HEAD~3

git commit --amend modifies the current HEAD commit. But how do I modify HEAD~3?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

白日梦 2024-08-05 03:05:07

使用很棒的交互式变基:

git rebase -i    # Show your commits in a text editor

找到所需的提交,将 pick 更改为 e (edit),然后保存并关闭文件。 Git 将回退到该提交,允许您:

  • 使用 git commit --amend 进行更改,或
  • 使用 git reset @~ 放弃最后一次提交,但不这样做对文件的更改(即带您到编辑文件但尚未提交时所在的位置)。

后者对于执行更复杂的操作(例如拆分为多个提交)很有用。

然后,运行 git rebase --continue,Git 将在修改后的提交之上重播后续更改。 可能会要求您修复一些合并冲突。

注意:@HEAD的简写,~是指定提交之前的提交。

阅读有关 Git 文档中的重写历史记录的更多信息。

不要害怕对

ProTip™ 进行变基:   不要害怕尝试重写历史记录的“危险”命令* — 默认情况下,Git 在 90 天内不会删除您的提交; 您可以在引用日志中找到它们:

$ git reset @~3   # go back 3 commits
$ git reflog
c4f708b HEAD@{0}: reset: moving to @~3
2c52489 HEAD@{1}: commit: more changes
4a5246d HEAD@{2}: commit: make important changes
e8571e4 HEAD@{3}: commit: make some changes
... earlier commits ...
$ git reset 2c52489
... and you're back where you started

* 但请注意 --hard--force 等选项 - 它们可能会丢弃数据。< br>
* 此外,不要重写您正在协作的任何分支上的历史记录。


在许多系统上,git rebase -i 将默认打开 Vim。 Vim 的工作方式与大多数现代文本编辑器不同,因此请查看如何使用 Vim 进行变基。 如果您想使用其他编辑器,请使用 git config --global core.editor your-favorite-text-editor 进行更改。

Use the awesome interactive rebase:

git rebase -i    # Show your commits in a text editor

Find the commit you want, change pick to e (edit), and save and close the file. Git will rewind to that commit, allowing you to either:

  • use git commit --amend to make changes, or
  • use git reset @~ to discard the last commit, but not the changes to the files (i.e. take you to the point you were at when you'd edited the files, but hadn't committed yet).

The latter is useful for doing more complex stuff like splitting into multiple commits.

Then, run git rebase --continue, and Git will replay the subsequent changes on top of your modified commit. You may be asked to fix some merge conflicts.

Note: @ is shorthand for HEAD, and ~ is the commit before the specified commit.

Read more about rewriting history in the Git docs.

Don't be afraid to rebase

ProTip™:   Don't be afraid to experiment with "dangerous" commands that rewrite history* — Git doesn't delete your commits for 90 days by default; you can find them in the reflog:

$ git reset @~3   # go back 3 commits
$ git reflog
c4f708b HEAD@{0}: reset: moving to @~3
2c52489 HEAD@{1}: commit: more changes
4a5246d HEAD@{2}: commit: make important changes
e8571e4 HEAD@{3}: commit: make some changes
... earlier commits ...
$ git reset 2c52489
... and you're back where you started

* Watch out for options like --hard and --force though — they can discard data.
* Also, don't rewrite history on any branches you're collaborating on.


On many systems, git rebase -i will open up Vim by default. Vim doesn't work like most modern text editors, so take a look at how to rebase using Vim. If you'd rather use a different editor, change it with git config --global core.editor your-favorite-text-editor.

千寻… 2024-08-05 03:05:07

当我需要修复以前的问题时,我经常使用与 --autosquash 交互的 rebase致力于更深入的历史。 它本质上加速了 ZelluX 的答案所说明的过程,并且当您需要编辑多个提交时特别方便。

从文档中:

--autosquash

当提交日志消息以“squash! …”(或“fixup! …”)开头,并且存在标题以相同 … 开头的提交时,自动修改 rebase -i 的待办事项列表,以便该提交标记为压缩紧随要修改的提交之后

假设您有如下所示的历史记录:

$ git log --graph --oneline
* b42d293 Commit3
* e8adec4 Commit2
* faaf19f Commit1

并且您有想要修改到 Commit2 的更改,然后使用

$ git commit -m "fixup! Commit2"

以下方式提交您的更改,或者您可以使用提交-sha 而不是提交消息,因此 "fixup! e8adec4 甚至只是提交消息的前缀。

之前对提交启动交互式变基

$ git rebase e8adec4^ -i --autosquash

然后在编辑器打开

pick e8adec4 Commit2
fixup 54e1a99 fixup! Commit2
pick b42d293 Commit3

,其中所有 提交都已正确排序你需要做的就是保存并退出

Interactive rebase with --autosquash is something I frequently use when I need to fixup previous commits deeper in the history. It essentially speeds up the process that ZelluX's answer illustrates, and is especially handy when you have more than one commit you need to edit.

From the documentation:

--autosquash

When the commit log message begins with "squash! …​" (or "fixup! …​"), and there is a commit whose title begins with the same …​, automatically modify the todo list of rebase -i so that the commit marked for squashing comes right after the commit to be modified

Assume you have a history that looks like this:

$ git log --graph --oneline
* b42d293 Commit3
* e8adec4 Commit2
* faaf19f Commit1

and you have changes that you want to amend to Commit2 then commit your changes using

$ git commit -m "fixup! Commit2"

alternatively you can use the commit-sha instead of the commit message, so "fixup! e8adec4 or even just a prefix of the commit message.

Then initiate an interactive rebase on the commit before

$ git rebase e8adec4^ -i --autosquash

your editor will open with the commits already correctly ordered

pick e8adec4 Commit2
fixup 54e1a99 fixup! Commit2
pick b42d293 Commit3

all you need to do is save and exit

万劫不复 2024-08-05 03:05:07

基于文档

修改旧提交或多次提交的消息messages

git rebase -i HEAD~3 

上面显示了当前分支上最近 3 次提交的列表,如果需要更多,请将 3 更改为其他内容。 该列表将类似于以下内容:

pick e499d89 Delete CNAME
pick 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.

在要更改的每条提交消息之前将 pick 替换为 reword。 假设您更改了列表中的第二个提交,您的文件将如下所示:

pick e499d89 Delete CNAME
reword 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.

保存并关闭提交列表文件,这将弹出一个新编辑器供您更改提交消息,更改提交消息并保存。

最后,强制推送修改后的提交。

git push --force

Based on Documentation

Amending the message of older or multiple commit messages

git rebase -i HEAD~3 

The above displays a list of the last 3 commits on the current branch, change 3 to something else if you want more. The list will look similar to the following:

pick e499d89 Delete CNAME
pick 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.

Replace pick with reword before each commit message you want to change. Let say you change the second commit in the list, your file will look like the following:

pick e499d89 Delete CNAME
reword 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.

Save and close the commit list file, this will pop up a new editor for you to change your commit message, change the commit message and save.

Finally, force-push the amended commits.

git push --force
穿越时光隧道 2024-08-05 03:05:07

运行:

$ git rebase --interactive commit_hash^

每个 ^ 表示您要编辑的提交数量,如果只有一个(您指定的提交哈希),则您只需添加一个 ^ 即可。

使用 Vim,您可以将要更改的提交的单词 pick 更改为 reword,然后保存并退出 (:wq)。 然后 git 会提示您标记为 reword 的每个提交,以便您可以更改提交消息。

您必须保存每条提交消息并退出 (:wq) 才能转到下一条提交消息

如果您想退出而不应用更改,请按 :q!

编辑:要在vim中导航,您可以使用j向上,k向下,h code> 向左走,l 向右走(所有这些都在 NORMAL 模式下,按 ESC 转到 NORMAL模式)。
要编辑文本,请按 i 以便进入插入文本的 INSERT 模式。
ESC 返回到 NORMAL 模式:)

更新:这是来自 github 列表的一个很棒的链接 如何使用 git 撤消(几乎)任何内容

Run:

$ git rebase --interactive commit_hash^

each ^ indicates how many commits back you want to edit, if it's only one (the commit hash that you specified), then you just add one ^.

Using Vim you change the words pick to reword for the commits you want to change, save and quit(:wq). Then git will prompt you with each commit that you marked as reword so you can change the commit message.

Each commit message you have to save and quit(:wq) to go to the next commit message

If you want to exit without applying the changes, press :q!

EDIT: to navigate in vim you use j to go up, k to go down, h to go left, and l to go right( all this in NORMAL mode, press ESC to go to NORMAL mode ).
To edit a text, press i so that you enter the INSERT mode, where you insert text.
Press ESC to go back to NORMAL mode :)

UPDATE: Here's a great link from github listing How to undo (almost) anything with git

晨曦慕雪 2024-08-05 03:05:07

完全非交互式命令(1)

我只是想共享一个为此使用的别名。 它基于非交互式交互式变基。 要将其添加到您的 git,请运行此命令(解释如下):

git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^"; }; f'

或者,也可以处理未暂存文件的版本(通过存储然后取消存储它们):

git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git stash -k && git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^" && git stash pop; }; f'

此命令的最大优点是它 >无vim


(1)考虑到 rebase 期间没有冲突,当然

用法

git amend-to <REV> # e.g.
git amend-to HEAD~1
git amend-to aaaa1111

名称 amend-to 恕我直言似乎很合适。 将流程与 --amend 进行比较:

git add . && git commit --amend --no-edit
# vs
git add . && git amend-to <REV>

解释

  • git config --global alias. '!' - 创建一个名为 的全局 git 别名,它将执行非 git 命令
  • f() { <身体>; }; f - 一个“匿名”bash 函数。
  • SHA=`git rev-parse "$1"`; - 将参数转换为 git revision,并将结果分配给变量 SHA
  • git commit --fixup " $SHA" - SHA 的修复提交。 请参阅 git-commit 文档
  • GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^"
    • git rebase --interactive "$SHA^" 部分已被其他答案涵盖。
    • --autosquashgit commit --fixup 结合使用,请参阅 git-rebase 文档了解更多信息
    • GIT_SEQUENCE_EDITOR=true 使整个事情变得非交互式。 我从这篇博文学到了这个技巧< /a>.


Completely non-interactive command(1)

I just thought I'd share an alias that I'm using for this. It's based on non-interactive interactive rebase. To add it to your git, run this command (explanation given below):

git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^"; }; f'

Or, a version that can also handle unstaged files (by stashing and then un-stashing them):

git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git stash -k && git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^" && git stash pop; }; f'

The biggest advantage of this command is the fact that it's no-vim.


(1)given that there are no conflicts during rebase, of course

Usage

git amend-to <REV> # e.g.
git amend-to HEAD~1
git amend-to aaaa1111

The name amend-to seems appropriate IMHO. Compare the flow with --amend:

git add . && git commit --amend --no-edit
# vs
git add . && git amend-to <REV>

Explanation

  • git config --global alias.<NAME> '!<COMMAND>' - creates a global git alias named <NAME> that will execute non-git command <COMMAND>
  • f() { <BODY> }; f - an "anonymous" bash function.
  • SHA=`git rev-parse "$1"`; - converts the argument to git revision, and assigns the result to variable SHA
  • git commit --fixup "$SHA" - fixup-commit for SHA. See git-commit docs
  • GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^"
    • git rebase --interactive "$SHA^" part has been covered by other answers.
    • --autosquash is what's used in conjunction with git commit --fixup, see git-rebase docs for more info
    • GIT_SEQUENCE_EDITOR=true is what makes the whole thing non-interactive. This hack I learned from this blog post.
山川志 2024-08-05 03:05:07

如果由于某种原因您不喜欢交互式编辑器,您可以使用 git rebase --onto 。

假设您要修改 Commit1。 首先,从之前 Commit1 开始分支:

git checkout -b amending [commit before Commit1]

其次,使用 cherry-pick 抓取 Commit1

git cherry-pick Commit1

现在,修改您的更改,创建 Commit1'

git add ...
git commit --amend -m "new message for Commit1"

最后,在隐藏任何其他更改后,将其余的提交移植到 master 之上
新提交:

git rebase --onto amending Commit1 master

读取:“变基,到分支amendingCommit1(不包含)和master(包含)之间的所有提交”。 即 Commit2 和 Commit3,完全删除旧的 Commit1。 你可以直接挑选它们,但这种方法更容易。

记得清理你的树枝!

git branch -d amending

If for some reason you don't like interactive editors, you can use git rebase --onto.

Say you want to modify Commit1. First, branch from before Commit1:

git checkout -b amending [commit before Commit1]

Second, grab Commit1 with cherry-pick:

git cherry-pick Commit1

Now, amend your changes, creating Commit1':

git add ...
git commit --amend -m "new message for Commit1"

And finally, after having stashed any other changes, transplant the rest of your commits up to master on top of your
new commit:

git rebase --onto amending Commit1 master

Read: "rebase, onto the branch amending, all commits between Commit1 (non-inclusive) and master (inclusive)". That is, Commit2 and Commit3, cutting the old Commit1 out entirely. You could just cherry-pick them, but this way is easier.

Remember to clean up your branches!

git branch -d amending
ˉ厌 2024-08-05 03:05:07

git stash + rebase自动化

当我需要多次修改旧提交以进行 Gerrit 审查时,我一直在这样做:

git-amend-old() (
  # Stash, apply to past commit, and rebase the current branch on to of the result.
  current_branch="$(git rev-parse --abbrev-ref HEAD)"
  apply_to="$1"
  git stash
  git checkout "$apply_to"
  git stash apply
  git add -u
  git commit --amend --no-edit
  new_sha="$(git log --format="%H" -n 1)"
  git checkout "$current_branch"
  git rebase --onto "$new_sha" "$apply_to"
)

< a href="https://github.com/cirosantilli/dotfiles/blob/72584f5126e59b6ef6a6658210df4a8d38c78dfd/home/.bashrc#L1824" rel="noreferrer">GitHub 上游。

用法:

  • 修改源文件,如果已经在仓库中,则无需 git add
  • git-amend-old $old_sha

我喜欢这个而不是 --autosquash因为它不会压制其他不相关的修复。

git stash + rebase automation

For when I need to modify an old commit a lot of times for Gerrit reviews, I've been doing:

git-amend-old() (
  # Stash, apply to past commit, and rebase the current branch on to of the result.
  current_branch="$(git rev-parse --abbrev-ref HEAD)"
  apply_to="$1"
  git stash
  git checkout "$apply_to"
  git stash apply
  git add -u
  git commit --amend --no-edit
  new_sha="$(git log --format="%H" -n 1)"
  git checkout "$current_branch"
  git rebase --onto "$new_sha" "$apply_to"
)

GitHub upstream.

Usage:

  • modify source file, no need to git add if already in repo
  • git-amend-old $old_sha

I like this over --autosquash as it does not squash other unrelated fixups.

狼性发作 2024-08-05 03:05:07

自动交互式变基编辑,然后提交恢复,准备重做

我发现自己经常修复过去的提交,以至于我为它编写了一个脚本。

工作流程如下:

  1. git commit-edit ; 
      

    这将使您到达您要编辑的提交。

  2. 按照您希望的方式修复并暂存提交。

    (您可能需要使用git stash save来保留您未提交的任何文件)

  3. 使用--amend重做提交,例如:

    git commit --amend 
      
  4. 完成变基:

    git rebase --继续 
      

为了使上述工作正常进行,请将以下脚本放入 $PATHgit-commit-edit 的可执行文件中>:

#!/bin/bash

set -euo pipefail

script_name=${0##*/}

warn () { printf '%s: %s\n' "$script_name" "$*" >&2; }
die () { warn "$@"; exit 1; }

[[ $# -ge 2 ]] && die "Expected single commit to edit. Defaults to HEAD~"

# Default to editing the parent of the most recent commit
# The most recent commit can be edited with `git commit --amend`
commit=$(git rev-parse --short "${1:-HEAD~}")
message=$(git log -1 --format='%h %s' "$commit")

if [[ $OSTYPE =~ ^darwin ]]; then
  sed_inplace=(sed -Ei "")
else
  sed_inplace=(sed -Ei)
fi

export GIT_SEQUENCE_EDITOR="${sed_inplace[*]} "' "s/^pick ('"$commit"' .*)/edit \\1/"'
git rebase --quiet --interactive --autostash --autosquash "$commit"~
git reset --quiet @~ "$(git rev-parse --show-toplevel)"  # Reset the cache of the toplevel directory to the previous commit
git commit --quiet --amend --no-edit --allow-empty  #  Commit an empty commit so that that cache diffs are un-reversed

echo
echo "Editing commit: $message" >&2
echo

Automated interactive rebase edit followed by commit revert ready for a do-over

I found myself fixing a past commit frequently enough that I wrote a script for it.

Here's the workflow:

  1. git commit-edit <commit-hash>
    

    This will drop you at the commit you want to edit.

  2. Fix and stage the commit as you wish it had been in the first place.

    (You may want to use git stash save to keep any files you're not committing)

  3. Redo the commit with --amend, eg:

    git commit --amend
    
  4. Complete the rebase:

    git rebase --continue
    

For the above to work, put the below script into an executable file called git-commit-edit somewhere in your $PATH:

#!/bin/bash

set -euo pipefail

script_name=${0##*/}

warn () { printf '%s: %s\n' "$script_name" "$*" >&2; }
die () { warn "$@"; exit 1; }

[[ $# -ge 2 ]] && die "Expected single commit to edit. Defaults to HEAD~"

# Default to editing the parent of the most recent commit
# The most recent commit can be edited with `git commit --amend`
commit=$(git rev-parse --short "${1:-HEAD~}")
message=$(git log -1 --format='%h %s' "$commit")

if [[ $OSTYPE =~ ^darwin ]]; then
  sed_inplace=(sed -Ei "")
else
  sed_inplace=(sed -Ei)
fi

export GIT_SEQUENCE_EDITOR="${sed_inplace[*]} "' "s/^pick ('"$commit"' .*)/edit \\1/"'
git rebase --quiet --interactive --autostash --autosquash "$commit"~
git reset --quiet @~ "$(git rev-parse --show-toplevel)"  # Reset the cache of the toplevel directory to the previous commit
git commit --quiet --amend --no-edit --allow-empty  #  Commit an empty commit so that that cache diffs are un-reversed

echo
echo "Editing commit: $message" >&2
echo
℉絮湮 2024-08-05 03:05:07

最好的选择是使用“交互式变基命令”

git rebase 命令非常强大。 它允许您编辑
提交消息、合并提交、重新排序......等等。

每次对提交进行变基时,都会为每个提交创建一个新的 SHA
commit 不管内容是否改变! 你应该
使用此命令时要小心,因为它可能会产生剧烈的影响
特别是当您与其他人合作时的影响
开发商。 当你在的时候他们可能会开始处理你的提交
重新调整一些基础。 在您强制推送提交后,它们将被排除
同步,稍后您可能会在混乱的情况下发现。 所以要小心!

建议在变基之前创建一个备份分支,以便
每当你发现事情失控时,你都可以回到原来的状态
之前的状态。

现在如何使用这个命令呢?

git rebase -i <base> 

-i 代表“交互式”。 请注意,您可以在非交互模式下执行变基。 ex:

#interactivly rebase the n commits from the current position, n is a given number(2,3 ...etc)
git rebase -i HEAD~n 

HEAD 表示您当前的位置(也可以是分支名称或提交 SHA)。 ~n 表示“n beforeé”,因此 HEAD~n 将是您当前所在的提交之前的“n”次提交的列表。

git rebase 有不同的命令,例如:

  • p 或 pick 来保持提交原样。
  • 保留提交的内容,但更改提交消息
  • squash:将此提交的更改合并到上一个提交(列表中位于其上方的提交)中
  • 。 ...等等

    注意:最好让 Git 与您的代码编辑器配合使用,以使事情变得更简单。 例如,如果您使用可视代码,您可以像这样添加 git config --global core.editor "code --wait" 。 或者您可以在 Google 中搜索如何将您喜欢的代码编辑器与 GIT 关联起来。

git rebase 示例

我想更改我所做的最后 2 个提交,因此我像这样处理:

  1. 显示当前提交:
    #这将在一行上显示所有提交 
      $git log --oneline 
      4f3d0c8(HEAD -> 文档)文档:添加项目描述和包含的文件” 
      4d95e08 文档:添加创建日期和项目标题” 
      eaf7978 (origin/master, origin/HEAD, master) 初始提交 
      46a5819 创建 README.md 
      
  2. 现在我使用 git rebase 来更改最后 2 条提交消息:
    $git rebase -i HEAD~2
    它打开代码编辑器并显示:

    pick 4d95e08 docs:添加创建日期和项目标题 
      pick 4f3d0c8 docs:添加项目描述和包含的文件 
    
      # 将 eaf7978..4f3d0c8 重新设置为 eaf7978(2 个命令) 
      # 
      # 命令: 
      # p,选择<提交>;   = 使用提交 
      # r,改写<提交>;   = 使用提交,但编辑提交消息 
      ... 
      

    因为我想更改这 2 个提交的提交消息。 因此,我将输入 rreword 来代替 pick。 然后保存文件并关闭选项卡。
    请注意,rebase 是在多步骤过程中执行的,因此下一步是更新消息。 另请注意,提交按时间倒序显示,因此最后一次提交显示在该提交中,第一个提交显示在第一行中,依此类推。

  3. 更新消息:
    更新第一条消息:

    docs:将创建日期和项目标题添加到文档“README.md”中 
    
      # 请输入您的更改的提交消息。   线路开始 
      # 和 '#' 将被忽略,空消息将中止提交。 
      ... 
      

    保存并关闭
    编辑第二条消息

    docs:将项目描述和包含的文件添加到文档“README.md”中 
    
      # 请输入您的更改的提交消息。   线路开始 
      # 和 '#' 将被忽略,空消息将中止提交。 
      ... 
      

    保存并关闭。

  4. 在变基结束时,您将收到类似这样的消息:成功变基并更新了 refs/heads/documentation 这意味着您成功了。 您可以显示更改:

    5dff827(HEAD -> 文档)文档:将项目描述和包含的文件添加到文档“README.md”中 
      4585c68 文档:将创建日期和项目标题添加到文档“README.md”中 
      eaf7978 (origin/master, origin/HEAD, master) 初始提交 
      46a5819 创建 README.md 
      

    我希望这可以帮助新用户:)。

The best option is to use "Interactive rebase command".

The git rebase command is incredibly powerful. It allows you to edit
commit messages, combine commits, reorder them ...etc.

Every time you rebase a commit a new SHA will be created for each
commit regardless of the content will be changed or not! You should be
careful when to use this command cause it may have drastic
implications especially if you work in collaboration with other
developers. They may start working with your commit while you're
rebasing some. After you force to push the commits they will be out of
sync and you may find out later in a messy situation. So be careful!

It's recommended to create a backup branch before rebasing so
whenever you find things out of control you can return back to the
previous state.

Now how to use this command?

git rebase -i <base> 

-i stand for "interactive". Note that you can perform a rebase in non-interactive mode. ex:

#interactivly rebase the n commits from the current position, n is a given number(2,3 ...etc)
git rebase -i HEAD~n 

HEAD indicates your current location(can be also branch name or commit SHA). The ~n means "n beforeé, so HEAD~n will be the list of "n" commits before the one you are currently on.

git rebase has different command like:

  • p or pick to keep commit as it is.
  • r or reword: to keep the commit's content but alter the commit message.
  • s or squash: to combine this commit's changes into the previous commit(the commit above it in the list).
  • ... etc.

    Note: It's better to get Git working with your code editor to make things simpler. Like for example if you use visual code you can add like this git config --global core.editor "code --wait". Or you can search in Google how to associate you preferred your code editor with GIT.

Example of git rebase

I wanted to change the last 2 commits I did so I process like this:

  1. Display the current commits:
    #This to show all the commits on one line
    $git log --oneline
    4f3d0c8 (HEAD -> documentation) docs: Add project description and included files"
    4d95e08 docs: Add created date and project title"
    eaf7978 (origin/master , origin/HEAD, master) Inital commit
    46a5819 Create README.md
    
  2. Now I use git rebase to change the 2 last commits messages:
    $git rebase -i HEAD~2
    It opens the code editor and show this:

    pick 4d95e08 docs: Add created date and project title
    pick 4f3d0c8 docs: Add project description and included files
    
    # Rebase eaf7978..4f3d0c8 onto eaf7978 (2 commands)
    #
    # Commands:
    # p, pick <commit> = use commit
    # r, reword <commit> = use commit, but edit the commit message
    ...
    

    Since I want to change the commit message for this 2 commits. So I will type r or reword in place of pick. Then Save the file and close the tab.
    Note that rebase is executed in a multi-step process so the next step is to update the messages. Note also that the commits are displayed in reverse chronological order so the last commit is displayed in that one and the first commit in the first line and so forth.

  3. Update the messages:
    Update the first message:

    docs: Add created date and project title to the documentation "README.md"
    
    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    ...
    

    save and close
    Edit the second message

    docs: Add project description and included files to the documentation "README.md"
    
    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    ...
    

    save and close.

  4. You will get a message like this by the end of the rebase: Successfully rebased and updated refs/heads/documentation which means that you succeed. You can display the changes:

    5dff827 (HEAD -> documentation) docs: Add project description and included files to the documentation "README.md"
    4585c68 docs: Add created date and project title to the documentation "README.md"
    eaf7978 (origin/master, origin/HEAD, master) Inital commit
    46a5819 Create README.md
    

    I wish that may help the new users :).

落在眉间の轻吻 2024-08-05 03:05:07

更改最后一次提交:

git commit --amend
// or
git commit --amend -m "an updated commit message"

不要修改公共提交
修改后的提交实际上是全新的提交,之前的提交将不再位于您当前的分支上。

例如,如果您想更改最后三个提交消息或该组中的任何提交消息,您可以将要编辑的最后一个提交的父级作为参数提供给 git rebase -i,即 HEAD~2 ^ 或 HEAD~3。 记住 ~3 可能更容易,因为您正在尝试编辑最后三个提交,但请记住,您实际上是在指定四个提交之前,即您要编辑的最后一个提交的父级:

$ git rebase -i HEAD~3

了解更多

Changing the Last Commit:

git commit --amend
// or
git commit --amend -m "an updated commit message"

Don’t amend public commits
Amended commits are actually entirely new commits and the previous commit will no longer be on your current branch.

For example, if you want to change the last three commit messages, or any of the commit messages in that group, you supply as an argument to git rebase -i the parent of the last commit you want to edit, which is HEAD~2^ or HEAD~3. It may be easier to remember the ~3 because you’re trying to edit the last three commits, but keep in mind that you’re actually designating four commits ago, the parent of the last commit you want to edit:

$ git rebase -i HEAD~3

know more

戏剧牡丹亭 2024-08-05 03:05:07

采用这种方法(它可能与使用交互式变基完全相同),但对我来说这很简单。

注意:我提出这种方法是为了说明您可以做什么,而不是日常替代方案。 因为它有很多步骤(可能还有一些注意事项。)

假设您想要更改提交 0 并且您当前正在 feature-branch

some-commit---0---1---2---(feature-branch)HEAD

签出此提交并创建一个 快速分支。 您还可以将功能分支克隆为恢复点(在开始之前)。

?(git checkout -b feature-branch-backup)
git checkout 0
git checkout -b quick-branch

您现在将看到类似这样的内容:

0(quick-branch)HEAD---1---2---(feature-branch)

阶段发生变化,隐藏其他所有内容。

git add ./example.txt
git stash

提交更改并检出回 feature-branch

git commit --amend
git checkout feature-branch

您现在将得到如下内容:

some-commit---0---1---2---(feature-branch)HEAD
           \
             ---0'(quick-branch)

feature-branch 重新设置为 quick-branch (解决任何冲突一路上)。 应用隐藏并删除 quick-branch

git rebase quick-branch
git stash pop
git branch -D quick-branch

你最终会得到:

some-commit---0'---1'---2'---HEAD(feature-branch)

Git 不会在变基时重复(虽然我不能真正说到什么程度)0 提交。

注意:所有提交哈希值都是从我们最初打算更改的提交开始更改的。

Came to this approach (and it is probably exactly the same as using interactive rebase) but for me it's kind of straightforward.

Note: I present this approach for the sake of illustration of what you can do rather than an everyday alternative. Since it has many steps (and possibly some caveats.)

Say you want to change commit 0 and you are currently on feature-branch

some-commit---0---1---2---(feature-branch)HEAD

Checkout to this commit and create a quick-branch. You can also clone your feature branch as a recovery point (before starting).

?(git checkout -b feature-branch-backup)
git checkout 0
git checkout -b quick-branch

You will now have something like this:

0(quick-branch)HEAD---1---2---(feature-branch)

Stage changes, stash everything else.

git add ./example.txt
git stash

Commit changes and checkout back to feature-branch

git commit --amend
git checkout feature-branch

You will now have something like this:

some-commit---0---1---2---(feature-branch)HEAD
           \
             ---0'(quick-branch)

Rebase feature-branch onto quick-branch (resolve any conflicts along the way). Apply stash and remove quick-branch.

git rebase quick-branch
git stash pop
git branch -D quick-branch

And you end up with:

some-commit---0'---1'---2'---HEAD(feature-branch)

Git will not duplicate (although I can't really say to what extent) the 0 commit when rebasing.

Note: all commit hashes are changed starting from the commit we originally intended to change.

骑趴 2024-08-05 03:05:07

要获取非交互式命令,请将包含此内容的脚本放入您的 PATH 中:

#!/bin/sh
#
# git-fixup
# Use staged changes to modify a specified commit
set -e
cmt=$(git rev-parse $1)
git commit --fixup="$cmt"
GIT_EDITOR=true git rebase -i --autosquash "$cmt~1"

通过暂存更改(使用 git add )来使用它,然后运行 ​​git fixup 。 当然,如果发生冲突,它仍然会是互动的。

To get a non-interactive command, put a script with this content in your PATH:

#!/bin/sh
#
# git-fixup
# Use staged changes to modify a specified commit
set -e
cmt=$(git rev-parse $1)
git commit --fixup="$cmt"
GIT_EDITOR=true git rebase -i --autosquash "$cmt~1"

Use it by staging your changes (with git add) and then run git fixup <commit-to-modify>. Of course, it will still be interactive if you get conflicts.

挖个坑埋了你 2024-08-05 03:05:07

我执行以下操作,包括更改本地提交的日期和时间:

git rebase -i HEAD~6

~6 是要显示的提交历史记录的数量。

  • 将要编辑的提交从 pick 更改为 edit
  • 然后我保存并退出(在 ubuntu 中:Ctrl+O 保存,Ctrl+X 退出)
    1. 然后我运行:git commit --amend --date="2022-09-02T19:10:04" -m "NEW_MSG"
  • 如果编辑已打开,只需保存并退出即可。
  • 然后,为了确认并转到下一次提交,或者如果是最后一次提交则完成,我执行:git rebase --continue

如果有更多提交需要编辑,则从第 1 点开始重复

最后,我验证更改,如果一切正常,我将执行 push

I do the following, including changing the date and time of local commits:

git rebase -i HEAD~6

~6 is the amount of commit history to display.

  • Change from pick to edit the commits to be edited.
  • Then I save and exit (In ubuntu: Ctrl+O to save and Ctrl+X to exit)
    1. Then I run: git commit --amend --date="2022-09-02T19:10:04" -m "NEW_MSG"
    1. If the edit is opened, just save and exit.
    1. Then to confirm and go to the next commit or finish if it is the last one, I execute: git rebase --continue

If there are more commits to edit, it is repeated from point 1

Finally I validate the changes and if everything is ok, I do the push

原谅过去的我 2024-08-05 03:05:07

我解决了这个问题,

1)通过创建新的提交并进行我想要的更改。2

r8gs4r commit 0

)我知道我需要与它合并哪个提交。 这是提交 3。

所以, git rebase -i HEAD~4 # 4 代表最近 4 次提交(这里提交 3 位于第四位)

3) 在交互式 rebase 中,最近提交将位于底部。 它看起来很相似,

pick q6ade6 commit 3
pick vr43de commit 2
pick ac123d commit 1
pick r8gs4r commit 0

4)如果你想与特定的合并,我们需要重新安排提交。 应该是这样,

parent
|_child

pick q6ade6 commit 3
f r8gs4r commit 0
pick vr43de commit 2
pick ac123d commit 1

重新排列后,您需要将 p pick 替换为 ffixup 将在没有提交消息的情况下合并) 或 ssquash 与提交消息合并可以在运行时更改)

,然后保存您的树。

现在与现有提交合并完成。

注意:除非您自己维护,否则这不是更好的方法。 如果
你的团队规模很大,这不是重写 git 的可接受方法
树最终会陷入你知道其他人不会发生的冲突。 如果你想
为了用更少的提交来保持你的树干净可以尝试这个,如果它
小团队,否则不优选......

I solved this,

1) by creating new commit with changes i want..

r8gs4r commit 0

2) i know which commit i need to merge with it. which is commit 3.

so, git rebase -i HEAD~4 # 4 represents recent 4 commit (here commit 3 is in 4th place)

3) in interactive rebase recent commit will located at bottom. it will looks alike,

pick q6ade6 commit 3
pick vr43de commit 2
pick ac123d commit 1
pick r8gs4r commit 0

4) here we need to rearrange commit if you want to merge with specific one. it should be like,

parent
|_child

pick q6ade6 commit 3
f r8gs4r commit 0
pick vr43de commit 2
pick ac123d commit 1

after rearrange you need to replace p pick with f (fixup will merge without commit message) or s (squash merge with commit message can change in run time)

and then save your tree.

now merge done with existing commit.

Note: Its not preferable method unless you're maintain on your own. if
you have big team size its not a acceptable method to rewrite git
tree will end up in conflicts which you know other wont. if you want
to maintain you tree clean with less commits can try this and if its
small team otherwise its not preferable.....

牵你的手,一向走下去 2024-08-05 03:05:07

如果您只想重写旧的提交消息而不更改分支上的哈希值,您可以使用:

git replace --edit <commit>

这将打开编辑器并显示如下内容:

tree 430db025986d2bf8791be16b370ec37a00f6924b
parent 77efdb98a6e021ca81cd96f7c8c05d25c09e0ad4
author John Doe <[email protected]> 1698219601 +0200
committer John Doe <[email protected]> 1698219601 +0200

<initial commit message>

修改消息并保存。

然后必须使用以下命令显式推送和获取修改后的引用:

git push origin 'refs/replace/*'
git fetch origin 'refs/replace/*:refs/replace/*'

If you only want to reword an old commit message without changing the hashes on the branch, you can use:

git replace --edit <commit>

This opens the editor and displays something like this:

tree 430db025986d2bf8791be16b370ec37a00f6924b
parent 77efdb98a6e021ca81cd96f7c8c05d25c09e0ad4
author John Doe <[email protected]> 1698219601 +0200
committer John Doe <[email protected]> 1698219601 +0200

<initial commit message>

Modify the message and save.

The modified references will then have to be pushed and fetched explicitly with:

git push origin 'refs/replace/*'
git fetch origin 'refs/replace/*:refs/replace/*'
独守阴晴ぅ圆缺 2024-08-05 03:05:07

对我来说,这是为了从存储库中删除一些凭据。
我尝试了变基,并在尝试变基 - 继续时遇到了大量看似无关的冲突。
不要费心去尝试 rebase 自己,在 mac 上使用名为 BFG (brew install bfg) 的工具。

For me it was for removing some credentials from a repo.
I tried rebasing and ran into a ton of seemingly unrelated conflicts along the way when trying to rebase --continue.
Don't bother attempting to rebase yourself, use the tool called BFG (brew install bfg) on mac.

愚人国度 2024-08-05 03:05:07

如果您还没有推送提交,那么您可以使用 git reset HEAD^[1,2,3,4...] 返回到之前的提交

例如

git commit <file1> -m "Updated files 1 and 2"
git commit <file3> -m "Updated file 3"

糟糕,忘记添加 file2到第一次提交...

git reset HEAD^1 // because I only need to go back 1 commit

git add <file2>

这会将 file2 添加到第一次提交。

If you haven't already pushed the commits then you can go back to a previous commit using git reset HEAD^[1,2,3,4...]

For example

git commit <file1> -m "Updated files 1 and 2"
git commit <file3> -m "Updated file 3"

Oops, forgot to add file2 to the first commit...

git reset HEAD^1 // because I only need to go back 1 commit

git add <file2>

This will add file2 to the first commit.

定格我的天空 2024-08-05 03:05:07

好吧,这个解决方案可能听起来很愚蠢,但在某些情况下可以拯救你。

我的一个朋友刚刚遇到不小心提交了一些巨大的文件(四个自动生成的文件,每个文件大小在 3GB 到 5GB 之间),然后在此基础上提交了一些额外的代码,然后才意识到< code>git push 不再工作了!

这些文件已在 .gitignore 中列出,但在重命名容器文件夹后,它们被暴露并提交了! 现在除此之外还有一些代码提交,但是 push 一直在运行(尝试上传 GB 的数据!),最终会因 Github 的文件大小限制

交互式变基或类似的问题是,他们需要处理这些巨大的文件,并且需要很长时间才能完成任何事情。 然而,在 CLI 中花费了近一个小时后,我们不确定这些文件(和增量)是否确实从历史记录中删除,或者只是不包含在当前提交中。 推送也不起作用,我的朋友真的被困住了。

所以,我想出的解决方案是:

  1. 将当前 git 文件夹重命名为 ~/Project-old
  2. 再次从 github 克隆 git 文件夹(到 ~/Project)。
  3. 结帐至同一分行。
  4. 手动 cp -r 将文件从 ~/Project-old 文件夹复制到 ~/Project
  5. 确保不需要签入的大量文件经过 mv 编辑,并正确包含在 .gitignore 中。
  6. 另请确保您不会用旧文件夹覆盖最近克隆的 ~/Project 中的 .git 文件夹。 这就是有问题的历史日志所在的地方!
  7. 现在查看更改。 它应该是所有最近提交的并集,不包括有问题的文件。
  8. 最后提交更改,并且被push'ed 了。

这个解决方案最大的问题是,它涉及手动复制一些文件,并且还将所有最近的提交合并为一个(显然带有一个新的提交哈希)。 B

最大的好处是,每一步都非常清晰,它非常适合大文件(以及敏感文件),并且不会在历史中留下任何痕迹!

Well, this solution might sound very silly, but can save you in certain conditions.

A friend of mine just ran into accidentally committing very some huge files (four auto-generated files ranging between 3GB to 5GB each) and then made some additional code commits on top of that before realizing the problem that git push wasn't working any longer!

The files had been listed in .gitignore but after renaming the container folder, they got exposed and committed! And now there were a few more commits of the code on top of that, but push was running forever (trying to upload GB of data!) and finally would fail due to Github's file size limits.

The problem with interactive rebase or anything similar was that they would deal with poking around these huge files and would take forever to do anything. Nevertheless, after spending almost an hour in the CLI, we weren't sure if the files (and deltas) are actually removed from the history or simply not included in the current commits. The push wasn't working either and my friend was really stuck.

So, the solution I came up with was:

  1. Rename current git folder to ~/Project-old.
  2. Clone the git folder again from github (to ~/Project).
  3. Checkout to the same branch.
  4. Manually cp -r the files from ~/Project-old folder to ~/Project.
  5. Make sure the massive files, that are not needed to be checked in are mved, and included in .gitignore properly.
  6. Also make sure you don't overwrite .git folder in the recently-cloned ~/Project by the old one. That's where the logs of the problematic history lives!
  7. Now review the changes. It should be the union of all the recent commits, excluding the problematic files.
  8. Finally commit the changes, and it's good to be push'ed.

The biggest problem with this solution is, it deals with manual copying some files, and also it merges all the recent commits into one (obviously with a new commit-hash.) B

The big benefits are that, it is very clear in every step, it works great for huge files (as well as sensitive ones), and it doesn't leave any trace in history behind!

美男兮 2024-08-05 03:05:07

我遇到了同样的问题,这个:

  1. 首先将分支复制为 x
  2. 然后硬休息到您想要返回的位置
  3. 然后修改新的更改
  4. 之后,从原始分支中挑选所有其他更改
  5. 签出原始分支
  6. 之前重置原始分支
  7. 在修改后的reversion rebase到x分支

我的骑手git日志:

git checkout -b x 77164a510f1c17ed650b87c2ebf0f7762ac6b2a2 --
git reset --hard 0d038b5e3e3e2adef4bd6aab7653f922c3fdc63f
git add --ignore-errors -A -f -- src/Mores.Warehouse.Core.Api.ClientSdk/Mores.Warehouse.Core.Api.ClientSdk.csproj
git commit -F C:\Users\Hassan\AppData\Local\Temp\git-commit-msg-.txt --amend --
git cherry-pick 77164a510f1c17ed650b87c2ebf0f7762ac6b2a2
git checkout feature/MOR-2947 --
git reset --hard 0d038b5e3e3e2adef4bd6aab7653f922c3fdc63f
git rebase x

I had same problem and this this:

  1. First duplicated the branch as x,
  2. Then hard rest to where you want to go back to
  3. Then amend new changes
  4. After that cherry pick all other changes from the original branch
  5. Checkout the original branch
  6. Reset the original branch before the amended reversion
  7. rebase into x branch

My rider git log:

git checkout -b x 77164a510f1c17ed650b87c2ebf0f7762ac6b2a2 --
git reset --hard 0d038b5e3e3e2adef4bd6aab7653f922c3fdc63f
git add --ignore-errors -A -f -- src/Mores.Warehouse.Core.Api.ClientSdk/Mores.Warehouse.Core.Api.ClientSdk.csproj
git commit -F C:\Users\Hassan\AppData\Local\Temp\git-commit-msg-.txt --amend --
git cherry-pick 77164a510f1c17ed650b87c2ebf0f7762ac6b2a2
git checkout feature/MOR-2947 --
git reset --hard 0d038b5e3e3e2adef4bd6aab7653f922c3fdc63f
git rebase x
む无字情书 2024-08-05 03:05:07

这是一个超级老的问题,但在搜索这个问题时仍然出现,所以我认为值得更新。 我的答案是 GitHub Desktop (obvs 仅适用于 github 存储库)。

今天,我能够通过转到我所在的存储库/分支的提交历史记录,然后一一执行它们来成功更新两个提交。 我还必须重新订购第二个,但这也很简单。 如果您不想冒险搞砸其他过程中的其中一个步骤,而只是想要一个干净的 UI,那么强烈建议您这样做。

This is a super old question, but it still comes up when searching for this issue, so I think it's worth updating. My answer is GitHub Desktop (which obvs only works for github repo's).

I was able to successfully update two commits today by going to the commit history for the repo/branch I'm in, and then doing them one by one. I had to also reorder the second one, but this was simple as well. Highly recommended if you don't want to risk screwing up one of the steps in the other procedures and just want a clean UI.

晚雾 2024-08-05 03:05:07

以下步骤帮助我们修改现有提交消息。

步骤 1. 键入 git rebase -i HEAD~N,其中 N 是要执行变基的提交数。 例如,如果您想更改第 4 个和第 5 个最新提交,您可以键入:

git rebase -i HEAD~5

步骤 2. 该命令将在默认文本编辑器中显示最新的 X 次提交:

pick 43f8707f9 fix: update dependency json5 to ^2.1.1
pick cea1fb88a fix: update dependency verdaccio to ^4.3.3
pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2
pick c5e078656 chore: update dependency flow-bin to ^0.109.0
pick 11ce0ab34 fix: Fix spelling.

#Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)

步骤 3. 移动到您想要的提交消息的行要更改并用 reword 替换 pick:

reword 43f8707f9 fix: update dependency json5 to ^2.1.1
reword cea1fb88a fix: update dependency verdaccio to ^4.3.3
pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2
pick c5e078656 chore: update dependency flow-bin to ^0.109.0
pick 11ce0ab34 fix: Fix spelling.

# Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)

步骤 4:保存更改并关闭编辑器。

第 5 步:对于每个选定的提交,都会打开一个新的文本编辑器窗口。 更改提交消息,保存文件,然后关闭编辑器。

fix: update dependency json5 to ^2.1.1

步骤 6:强制将更改推送到远程存储库:

git push --force <remoteName> <branchName>

Following steps help us to modify existing commit message.

Step 1. Type git rebase -i HEAD~N, where N is the number of commits to perform a rebase on. For example, if you want to change the 4th and the 5th latest commits, you would type:

git rebase -i HEAD~5

Step 2.The command will display the latest X commits in your default text editor :

pick 43f8707f9 fix: update dependency json5 to ^2.1.1
pick cea1fb88a fix: update dependency verdaccio to ^4.3.3
pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2
pick c5e078656 chore: update dependency flow-bin to ^0.109.0
pick 11ce0ab34 fix: Fix spelling.

#Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)

Step 3. Move to the lines of the commit message you want to change and replace pick with reword:

reword 43f8707f9 fix: update dependency json5 to ^2.1.1
reword cea1fb88a fix: update dependency verdaccio to ^4.3.3
pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2
pick c5e078656 chore: update dependency flow-bin to ^0.109.0
pick 11ce0ab34 fix: Fix spelling.

# Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)

Step 4: Save the changes and close the editor.

Step 5: For each chosen commit, a new text editor window will open. Change the commit message, save the file, and close the editor.

fix: update dependency json5 to ^2.1.1

Step 6: Force push the changes to the remote repository:

git push --force <remoteName> <branchName>
眼前雾蒙蒙 2024-08-05 03:05:06

使用 git rebase。 例如,要修改提交 bbc643cd,请运行:

git rebase --interactive bbc643cd~

请注意命令末尾的波形符 ~,因为您需要在 < 的上一个提交之上重新应用提交代码>bbc643cd(即bbc643cd~)。

在默认编辑器中,将提及 bbc643cd 的行中的 pick 修改为 edit

保存文件并退出。 git 会解释并自动执行文件中的命令。 您会发现自己处于之前刚刚创建提交 bbc643cd 的情况。

此时,bbc643cd 是您的最后一次提交,您可以 轻松修改。 进行更改,然后使用以下命令提交它们:

git commit --all --amend --no-edit

之后,使用以下命令返回到之前的 HEAD 提交:

git rebase --continue

警告:请注意,这将更改该提交的 SHA-1 以及所有孩子——换句话说,这重写了从那时起的历史。 如果使用命令 git push --force 进行推送,则可以中断存储库执行此操作

Use git rebase. For example, to modify commit bbc643cd, run:

git rebase --interactive bbc643cd~

Please note the tilde ~ at the end of the command, because you need to reapply commits on top of the previous commit of bbc643cd (i.e. bbc643cd~).

In the default editor, modify pick to edit in the line mentioning bbc643cd.

Save the file and exit. git will interpret and automatically execute the commands in the file. You will find yourself in the previous situation in which you just had created commit bbc643cd.

At this point, bbc643cd is your last commit and you can easily amend it. Make your changes and then commit them with the command:

git commit --all --amend --no-edit

After that, return back to the previous HEAD commit using:

git rebase --continue

WARNING: Note that this will change the SHA-1 of that commit as well as all children -- in other words, this rewrites the history from that point forward. You can break repos doing this if you push using the command git push --force.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文