Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何将所有更改还原到远程功能分支?_Git_Bitbucket - Fatal编程技术网

Git 如何将所有更改还原到远程功能分支?

Git 如何将所有更改还原到远程功能分支?,git,bitbucket,Git,Bitbucket,所以我有一个远程功能分支,它是几天前从master中提取的。在这段时间内,添加了一些文件。我对我的feature branch feature/XYZ的PR做了几次提交,然后我想挤压最近的,所以我按照所有正确的挤压步骤进行挤压,然后突然git不让我提交到我的远程分支。我得到了以下错误: error: failed to push some refs to 'ssh://git@............git' hint: Updates were rejected because the tip

所以我有一个远程功能分支,它是几天前从master中提取的。在这段时间内,添加了一些文件。我对我的feature branch feature/XYZ的PR做了几次提交,然后我想挤压最近的,所以我按照所有正确的挤压步骤进行挤压,然后突然git不让我提交到我的远程分支。我得到了以下错误:

error: failed to push some refs to 'ssh://git@............git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
所以我上网查找问题所在,我尝试了从git fetch到git pull的所有方法——从重新设置基址到将git分支设置为上游或诸如此类的方法,但似乎没有任何效果。所以我决定我现在不需要压缩提交,只想回到以前,因为我有一些重要的东西要处理和提交。我最后的办法是在我的系统上保存文件,删除功能分支,从头开始提交另一份PR,但如果有其他选择,我不想这样做


当我提交代码行中的更改时,它工作得很好。是否可能忘记我曾经压缩过更改并返回到与远程分支相同的状态和更改?

检查与功能分支关联的远程跟踪分支

git switch yourFeatureBranch
# or (older git)
git checkout yourFeatureBranch

git branch -avv
你应该看到:

* yourFeatureBranch  <sha> [origin/yourFeatureBranch]

这将强制更新远程
origin/yourFeatureBranch

push--force
可能会起作用,但它看起来会给其他开发人员带来灾难。最好是拉、合并、删除所需内容并向后推。我不想推给master,只想推给我自己的功能分支。后者的确切命令是什么?
git push --force -u origin yourFeatureBranch:yourFeatureBranch