Git:推动修改的提交 [英] Git: pushing amended commits

查看:132
本文介绍了Git:推动修改的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个项目,并在两个不同的地点使用机器来完成此项目。我为我正在工作的功能创建了一个分支,当我完成了一些工作后,我修改了对该分支的提交并将其推送到服务器,以便我可以从我的另一台计算机上停下来。



当我尝试发送修改后的提交时,它会拒绝我的推送。我认为这是因为我推送了一个旨在摧毁功能分支的当前HEAD的提交。我通常只使用--force。



有没有更好的方法来做到这一点?

  mike @ sleepycat:〜/ projects / myproject $ git pull origin topx 
从heroku.com:myproject
* branch topx - > FETCH_HEAD
已经是最新的。
mike @ sleepycat:〜/ projects / myproject $ git add app / models / reward.rb
mike @ sleepycat:〜/ projects / myproject $ git commit --amend
[topx 82a9880]添加topX奖励
9个文件已更改,106个插入(+),21个删除( - )
重写app / views / ceo / _reward_criteria.html.erb(96%)
创建模式100644 public /javascripts/jquery.multiselect.min.js
创建模式100644 public / site / javascripts / jquery.multiselect.min.js
创建模式100644 public / stylesheets / jquery.multiselect.css
mike @ sleepycat:〜/ projects / myproject $ git push origin topx
到git@heroku.com:myproject.git
! [已拒绝] topx - > topx(非快进)
错误:未能将某些参考文献推送到'git@heroku.com:myproject.git'
为防止您丢失历史记录,非快进更新被拒绝
在再次推送之前合并远程更改。有关详细信息,请参阅'git push --help'的'关于
快速转发的注意事项'部分。


解决方案

没有办法覆盖远程分支,在这种情况下的力量。您有2个选项:


  • 继续使用 git push --force

  • 不要使用 - 修改。如果你做的一些工作值得单独提交(足够稳定,编译,传递更多的测试等),创建新的提交。如果不是,则创建临时分支(如果分支为 my-feature ),并创建临时分支(如 my-feature-unstable 那里。当它再次变得稳定时,可以执行 git reset --soft my-feature checkout my-feature commit 在你的分支中从几个未完成的提交中创建单个提交。之后,可以删除临时分支。


I am currently working on a project and using machines in two different locations to do it. I have created a branch for the feature I am working on and when I finish some work on it I amend my commit to that branch and push it to the server so I can pick up where I left off on my other machine.

When I try to send my amended commit it rejects my push. I assume this is because I am pushing up a commit that is intended to clobber the current HEAD of the feature branch. I typically just use --force.

Is there a better way to do this?

mike@sleepycat:~/projects/myproject$ git pull origin topx
From heroku.com:myproject
 * branch            topx       -> FETCH_HEAD
Already up-to-date.
mike@sleepycat:~/projects/myproject$ git add app/models/reward.rb
mike@sleepycat:~/projects/myproject$ git commit --amend
[topx 82a9880] Added topX reward
 9 files changed, 106 insertions(+), 21 deletions(-)
 rewrite app/views/ceo/_reward_criteria.html.erb (96%)
 create mode 100644 public/javascripts/jquery.multiselect.min.js
 create mode 100644 public/site/javascripts/jquery.multiselect.min.js
 create mode 100644 public/stylesheets/jquery.multiselect.css
mike@sleepycat:~/projects/myproject$ git push origin topx
To git@heroku.com:myproject.git
 ! [rejected]        topx -> topx (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:myproject.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

解决方案

There is no way to overwrite remote branch without --force in this case. You have 2 options:

  • continue to use git push --force
  • don't use --amend. If some work you've done deserves a separate commit (is stable enough, compiling, passing more tests, etc...), create new commit. If not, create temporary branch (something like my-feature-unstable if your branch is my-feature) and commit there. When it becomes stable again, you can do git reset --soft my-feature, checkout my-feature and commit to create single commit in your branch from several unfinished commits. After that, temporary branch can be deleted.

这篇关于Git:推动修改的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆