我不能用git做很多事情,我想从我的仓库中删除一个提交,因为我上传了错误的东西.
我使用git revert <the_commit>
但是因为提交是root而我无法删除它.致命:无法恢复根提交
在那种情况下该怎么办?
请不要在这里给我链接到其他主题,我读了它们,我不明白该怎么做,我需要一些关于删除一些提交的基本示例.
我试图在主人之上重新分支一个分支,这是我以前做过的一千次.但今天它没有用:
> git status
On branch mystuff
Your branch and 'master' have diverged,
and have 6 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
> git rebase
First, rewinding head to replay your work on top of it...
> git status
On branch mystuff
Your branch is up-to-date with 'master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
[a directory from …
Run Code Online (Sandbox Code Playgroud) 使用的--keep-empty
选项时遇到一些麻烦git rebase
,并且不确定是否误解了该选项的作用,还是有错误。
这是一个最小的示例:
创建一个新的Git存储库和一个初始的,不相关的提交。
$ git init
$ echo something >base.txt
$ git add base.txt
$ git commit -m 'some base commit to not run into the root corner case'
Run Code Online (Sandbox Code Playgroud)创建一个新的提交,添加两个新文件。
$ echo A >a.txt; echo B >b.txt
$ git add a.txt b.txt
$ git commit -m 'add A and B'
Run Code Online (Sandbox Code Playgroud)修改其中一个文件。
$ echo A1 >a.txt
$ git add a.txt
$ git commit -m 'change A'
Run Code Online (Sandbox Code Playgroud)修改另一个文件。
$ echo B1 >b.txt
$ git add b.txt …
Run Code Online (Sandbox Code Playgroud)使用git 2.11,git rebase文档说:
如果提供了--onto选项,则当前分支将重置为<upstream>或<newbase>.这与git reset --hard(或)具有完全相同的效果.ORIG_HEAD设置为在重置之前指向分支的尖端.
我理解它upstream
并且newbase
指向相同的"基本引用",这意味着下面的两个rebase语法是等价的:
git rebase ABC
git rebase --onto ABC
Run Code Online (Sandbox Code Playgroud)
这是我设置的演示.让我们假设当前分支是FeatureABC
与远程分支完全同步.
#---create two identical branches, behind current branch by 5 commits
(FeatureABC) git branch Demo1-Rebase-ABC HEAD~4
(FeatureABC) git branch Demo2-Rebase-onto-ABC HEAD~4
#---Make a new commit in branch Demo1
git checkout Demo1-Rebase-ABC
echo "Demo of: git rebase FeatureABC Demo1-Rebase-ABC" > ./Demo1_BogusFile.txt
git add ./Demo1_BogusFile.txt
git commit -m "Create file Demo1_BogusFile.txt"
git rebase FeatureABC
Run Code Online (Sandbox Code Playgroud)
首先,倒带头重播你的工作
...应用:创建文件Demo1_BogusFile.txt
git log --oneline -3 …