我不小心将错误的文件提交给Git,但我还没有将提交推送到服务器.
如何从本地存储库中撤消这些提交?
master创建了一个新的分支,我们称之为test.
有几个开发人员要么提交master或创建其他分支,然后再合并master.
假设工作test需要几天时间,并且您希望不断test更新内部提交master.
我会做git pull origin master的test.
问题1:这是正确的方法吗?其他开发人员可以轻松地处理相同的文件,就像我工作顺便说一句.
我的工作test已经完成,我准备把它合并回来master.以下是我能想到的两种方式:
A:
git checkout test
git pull origin master
git push origin test
git checkout master
git pull origin test
Run Code Online (Sandbox Code Playgroud)
B:
git checkout test
git pull origin master
git checkout master
git merge test
Run Code Online (Sandbox Code Playgroud)
我没有使用,--rebase因为根据我的理解,rebase将从中获取更改master并将其叠加在其上,因此它可以覆盖其他人所做的更改.
问题2:这两种方法中哪一项是正确的?那有什么区别?
所有这一切的目标是让我的test分支更新所发生的事情,master然后我可以将它们合并回master希望保持时间线尽可能线性.
我试图将2个提交合并为1,所以我从git准备好跟随"压缩提交与rebase".
我跑了
git rebase --interactive HEAD~2
Run Code Online (Sandbox Code Playgroud)
在生成的编辑器中,我更改pick为squash然后保存退出,但是rebase因错误而失败
没有先前的提交,不能'挤压'
既然我的工作树已达到这种状态,我就无法恢复了.命令git rebase --interactive HEAD~2失败
交互式rebase已经开始
并git rebase --continue失败了
没有先前的提交,不能'挤压'
我是GitHub的新手.今天我在尝试将代码推送到GitHub时遇到了一些问题.
Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@github.com:519ebayproject/519ebayproject.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
我还没有在存储库中推送任何东西,为什么我需要拉东西呢?
这就是我在我所谓的稳定分支上所做的事情......
% git rebase master
First, rewinding head to replay your work on top of it...
Fast-forwarded alpha-0.3.0 to master.
% git status
# On branch alpha-0.3.0
# Your branch is ahead of 'origin/alpha-0.3.0' by 53 commits.
#
nothing to commit (working directory clean)
% git push
Fetching remote heads...
refs/
refs/heads/
refs/tags/
refs/remotes/
'refs/heads/master': up-to-date
updating 'refs/heads/alpha-0.3.0'
from cc4b63bebb6e6dd04407f8788938244b78c50285
to 83c9191dea88d146400853af5eb7555f252001b0
done
'refs/heads/unstable': up-to-date
Updating remote server info
Run Code Online (Sandbox Code Playgroud)
这是我后来意识到的一个错误.我想撤消整个过程,并将alpha-0.3.0分支恢复到原来的状态.
我该怎么办?
随着git rebase --interactive <commit>你能够压制任意数量的提交连成一个单一的一个.
除非你想将提交压缩到初始提交中,否则这一切都很棒.这似乎是不可能的.
有没有办法实现它?
在一个相关的问题中,我设法提出了一种不同的方法来解决第一次提交的问题,这也就是说,它是第二次提交.
如果您有兴趣:git:如何插入提交作为第一个,转移所有其他?
这给出了压缩多个提交的一个很好的解释:
http://git-scm.com/book/en/Git-Branching-Rebasing
但它不适用于已被推送的提交.如何在我的本地和远程回购中压缩最近几次提交?
编辑:当我这样做时git rebase -i origin/master~4 master,保留第一个pick,将其他三个设置为squash,然后退出(通过emacs中的cx cc),我得到:
$ git rebase -i origin/master~4 master
# Not currently on any branch.
nothing to commit (working directory clean)
Could not apply 2f40e2c... Revert "issue 4427: bpf device permission change option added"
$ git rebase -i origin/master~4 master
Interactive rebase already started
Run Code Online (Sandbox Code Playgroud)
其中2f40是pick提交.现在,4个提交中没有一个出现git log.我希望我的编辑器能够重新启动,以便我可以输入提交消息.我究竟做错了什么?
你如何将整个存储库压缩到第一次提交?
我可以重新设置第一次提交,但这会让我有2次提交.有没有办法在第一个之前引用提交?
我在本地存储库上有一堆提交,它们在主题上相似.在推送到遥控器之前,我想将它们组合成一个提交.我该怎么做?我认为rebase这样做,但我无法理解文档.
我创建了新的分支master:
git checkout -b testbranch
我做了20次提交.
现在我要压缩那20个提交.我这样做:
git rebase -i HEAD~20
如果我不知道有多少提交怎么办?有什么方法可以做以下事情:
git rebase -i all on this branch
git ×10
squash ×3
git-merge ×2
git-rebase ×2
rebase ×2
git-branch ×1
git-commit ×1
git-push ×1
git-squash ×1
pre-commit ×1
undo ×1