Git 推送到原点/主控位置。如何恢复

Git 推送到原点/主控位置。如何恢复,git,github,Git,Github,master是来自GitHub的受保护分支,所以我认为这永远不会发生,但我错了。在github上没有恢复的拉取请求 因此,我认为从origin/master分支可以节省一步,而不是从本地master分支。从原点/主节点分支出来的分支称为feature-x 我作出了两项承诺(按顺序为SHAs 718016d和8ab1912)。然后我做了一个git pull&&git push,它似乎将origin/master合并到了我的分支中,并推入origin/master。从我分支到我执行git拉取,大约有

master是来自GitHub的受保护分支,所以我认为这永远不会发生,但我错了。在github上没有恢复的拉取请求

因此,我认为从origin/master分支可以节省一步,而不是从本地master分支。从原点/主节点分支出来的分支称为
feature-x

我作出了两项承诺(按顺序为SHAs 718016d和8ab1912)。然后我做了一个
git pull&&git push
,它似乎将origin/master合并到了我的分支中,并推入origin/master。从我分支到我执行git拉取,大约有40次提交

如何从源/主历史记录中完全删除2次提交?我读到,删除已经公开的提交是一个非常糟糕的主意,但这是我理想的解决方案。如果有人能建议我如何以安全的方式做这件事

如果应该避免这种技术

我如何在本地恢复这些提交,并将其推回到原始/主服务器?我查看了git revert,但我想确保在我再次把事情搞砸之前,我知道到底发生了什么

添加日志:

git pub
是一个别名

pub = "!f() { git push -u ${1:-origin} `git symbolic-ref HEAD`; }; f"


有两种方法可以从git恢复提交:

1.使用git-rebase-i HEAD ~将其从历史记录中完全删除。这将打开一个窗口并列出提交。在这里,只需删除包含不需要的提交的行。然后保存并退出。但正如您所建议的,这是一个坏主意,因为它会修改git历史记录,并且需要您强制推送分支(因为这不是一个附加更改)。但是如果你这样做,那看起来好像那两个提交从未出现过


2.使用
git revert
。这是您可以选择的最安全的选项。这实际上并不删除任何提交。这只需添加一个新的提交,完全撤销提交所做的操作,并创建一个新的提交。这并不影响历史。这是一个附加更改,因此不需要强制推送。

“似乎”->包括日志输出。如果您在一个分支上执行了一个
git pull
(没有其他参数),那么该命令会将该分支的原始版本拉入该分支的本地版本。
git推送
同样适用于当前分支。不清楚您实际做了什么。@crashmstr如果OP是从
源代码/master
创建分支的,那么这就是分支将跟踪和推拉的内容。@Quentin是的,如果他们创建了一个新分支并将其设置为活动状态,则对该分支进行提交,在
push
pull
命令中没有引用origin/master,那么是:它们只会对新分支进行更改,并且origin/master不会因为这些操作而更改。@Quentin我明白你的意思:如果它们将新分支设置为跟踪origin/master,那么是的。但我不认为人们通常会这样做,或者在不传递额外参数的情况下可以这样做。正常的过程是
feature-x
将其上游设置为
origin/feature-x
。git bash addddo的日志我必须恢复合并中的所有提交,或者仅恢复我的commits@LearningJrDev有多少额外(不需要的)提交被推送到主服务器?顺便问一下,你能提供从创建本地分支到推动分支的确切命令吗?
C:\source\ [feature-x ↓1 ↑1 +6 ~8 -0 !]> git add -A; git commit -m "wip"
[feature-x 718016d8a] wip
 14 files changed, 358 insertions(+), 7 deletions(-)
------Lines removed for anonomity-------
C:\source\ [feature-x ↓1 ↑2]> git pub
To https://github.com/*********
 ! [rejected]            feature-x -> master (fetch first)
error: failed to push some refs to 'https://github.com/********.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
C:\source\ [feature-x ↓1 ↑2]> git pull
remote: Counting objects: 331, done.
remote: Compressing objects: 100% (118/118), done.
Receiving objects: 100% (331/331), 88.21 KiB | 0 bytes/s, done.sed 0Receiving objects:  27% (90/331)

Resolving deltas: 100% (254/254), completed with 78 local objects.
From https://github.com/********
------Lines removed for anonomity-------
Merge made by the 'recursive' strategy.
------Lines removed for anonomity-------
 27 files changed, 190 insertions(+), 44 deletions(-)
------Lines removed for anonomity-------
C:\source\ [feature-x ↑3]> git pub
Counting objects: 54, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (53/53), done.
Writing objects: 100% (54/54), 7.41 KiB | 0 bytes/s, done.
Total 54 (delta 42), reused 0 (delta 0)
remote: Resolving deltas: 100% (42/42), completed with 28 local objects.
Branch feature-x set up to track remote branch master from origin.
To https://github.com/*********