git:从我的私有分支

时间:2015-12-24 05:15:19

标签: git github

我从我们的github的主要仓库分叉,并根据需求对我的分支中的现有文件进行了更改。后来我承诺并将我的更改推送到我的私人分支机构。当我发送一个pull请求来合并主分支中的更改时,我被告知根据我编写的功能将我的代码移动到一个新文件。

我不知道如何在我的仓库中恢复推送的文件,以确定它在原始/主仓库中的含义?

请让我知道如何实现同样的目标。

3 个答案:

答案 0 :(得分:0)

执行git reset --soft HEAD~将恢复分支上的最后一次提交。

然后您可以进行必要的更改并提交。将您的更改合并到master。

答案 1 :(得分:0)

我认为你不一定要恢复你所做的任何事情,假设你想要保留你已推送的代码。您只需将文件移动到新位置并可能更改名称,然后将此更改推送到远程分支。 GitHub将自动检测您的远程分支已更新,然后可以完成拉取请求。

移动文件并重命名后,您可以有两个选项。第一个是简单地提交工作并推送:

git commit -m 'Renamed file and moved to a new location'
git push origin yourBranch

这将在远程分支的顶部创建 new 提交。另一种选择是修改 HEAD提交,并强制推送到存储库:

git commit --amend -m 'Renamed file and moved to a new location'
git push --force origin yourBranch

这将简单地更新远程分支的HEAD上的提交。无论您希望如何解决此问题,您的功能分支都将作为单个合并提交显示在master分支中,并且您的拉取请求可以完成。

答案 2 :(得分:0)

删除您当地的不受欢迎的提交

// sha1 to your last desired commit that you want to keep
git reset HEAD <sha1>

// create new branch 
git checkout <new_branch>

// delete old branch
git branch -D <old branch>

// Overwrite remote branch with the removed code
git checkout <old branch>
git push origin <new_branhc>
相关问题