前面道歉,我是一个有抱负的git guru,但还不是那里......
我目前有5个本地提交尚未被推送到我的远程分支;前两个禁止我推送,因为他们在某些源文件中有尾随/前导空格错误。
当我试图推动......
$ git push -u origin my-branch
我收到以下错误...
$ git push -u origin my-branch
Counting objects: 124, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (122/122), done.
Writing objects: 100% (124/124), 23.19 KiB | 3.31 MiB/s, done.
Total 124 (delta 94), reused 2 (delta 2)
remote: Resolving deltas: 100% (94/94), completed with 16 local objects.
remote: bin/pre_receive_hook: failed with exit status 1
remote: Starting pre_receive_hook.rb at 02:30:52.384
remote: Updating refs/heads/my-branch from 89e1e6deeec412a914c4cfc4c6dec101b15ba4c5 to 0cd270067efecff743505d6613c2cff07a4f7f14
remote: Running Conventions Check...
remote: Starting ConventionCheck at 02:30:53.162
remote: Checking Commit 0cd270067: OB-221 Remove pry bindings left in spec, remove leading/trailing spaces in files, add newline to end of files
remote: Checking Commit 1342336cd: OB-221 Remove pry bindings left in spec
remote: Checking Commit 7dc993531: OB-221 Refactored SoapRequest and CalculateInvoiceTaxRequest to accomodate a more traditional Adapter pattern
remote: Trailing/Leading spaces error, use --check in your diff to see the problem: Conventions
To github.my-site.com:my-site/argh_express.git
! [remote rejected] OB-221-taxware-api-adapter -> OB-221-taxware-api-adapter (pre-receive hook declined)
error: failed to push some refs to 'git@github.my-site.com:on-site/argh_express.git'
我已将使用
提交给前两(2)次提交的源文件的尾随/前导空格错误缩小 $ git diff --check -R 7dc993531 bbfd2723d
产生以下输出(由\ b表示的尾随空格)
ROOT/rails/app/models/integration/tax_ware/calculate_invoice_tax_result_model.rb:100: trailing whitespace.
+\b\b\b\b\b\b\b
ROOT/rails/spec/models/integration/tax_ware/soap_request_spec.rb:17: trailing whitespace.
+\b\b
ROOT/rails/spec/models/integration/tax_ware/soap_request_spec.rb:18: trailing whitespace.
+ let(:soap_request) do\b
因此错误提交如下(以粗体标记)
我基本上想要
但是,最近的提交并不包含需要推送的所有文件!如何推送最新的本地提交,包括我需要的所有文件,并丢弃所有以前的本地提交?
答案 0 :(得分:1)
在您的情况下,您只想在新提交中获得当前更改并且之前没有推送任何提交,交互式rebase实际上是过度杀伤。最简单的方法是执行软重置回到以前的版本并进行新的提交:
git reset --soft bbfd2723d^
这将在您提交之前将头移回,但保持工作目录和索引不变。然后,您可以像平常一样构建新的提交。
作为参考,git book章节tidyselect
中描述了这种方法。
答案 1 :(得分:0)
由于您要放弃较早的评论并单独推送最新的提交,git rebase -I
会对您有所帮助。
# activate `git rebase` on the last 5 commits on your branch
git rebase -i HEAD~5
您现在有以下选择(pick
和reword
除外):
edit
:单独更改提交squash
:将提交压缩到上一次提交,但将两个提交消息合并为一个提交消息fixup
:将提交压缩为上一个但丢弃当前提交消息如果您想保留5条提交消息的记录,请选择squash
其他fixup
,如下例所示:
pick bbfd2723d
fixup 9ca4f853f
fixup 7dc993531
fixup 1342336cd
fixup 0cd270067
pick
您要调整的最旧的提交以及squash / fixup
后续提交。reword
而不是pick
,以便最终的提交消息反映最终的差异。