Git:如何修改服务器的提交?

发布于 2024-12-10 23:09:10 字数 136 浏览 0 评论 0原文

我已经在 EC2 上的 git 服务器上推送了一些提交,而不是在 github 上。

如何修改 git 服务器上的这些提交?

操作就像 删除提交,例如变基, 更改提交消息

可能吗?

非常感谢。

I have already push some commits on my git server on EC2 , not on github.

How can I modify those commits on the git server?

Operation like
remove commit, like rebasing,
change commit message

Is it possible?

Thanks so much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

欲拥i 2024-12-17 23:09:10

您可以通过强制推动来完成几乎所有事情。将您的本地树更改为您想要的树,然后 git push -f 它将用您本地的树替换服务器上的树。值得注意的是,这会给任何其他拉动您刚刚替换的树的存储库带来麻烦。

You can do just about everything with a forced push. Change your local tree to exactly what you want and git push -f and it will replace the tree on the server with what you have locally. It's worth noting that this will cause trouble with any other repos that have pulled the tree you just replaced.

末骤雨初歇 2024-12-17 23:09:10

如果您想破坏性地编辑远程分支的历史记录(例如rebase/amend),请在本地进行更改,然后执行git push --force 。有时它不起作用(存储库管理员可以禁用此功能);在这种情况下,您可以尝试使用 git push origin :my_branch 删除远程分支,然后使用 git push origin my_branch 再次推送。否则,您可以使用 git revert,如果您在团队中工作,这是推荐的方式(经验法则是不应修改已发布的历史记录)。

下面是一个示例(使用 此 Github 存储库):

$ touch SOMETHING
$ emacs SOMETHING 
$ git add SOMETHING 
$ git ci -m SOMETHING
[master d14aaa0] SOMETHING
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 SOMETHING
$ git push
Counting objects: 8, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 611 bytes, done.
Total 6 (delta 3), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
   53f836a..d14aaa0  master -> master
$ git reset --hard "HEAD~"
HEAD is now at 7b2dc96 TODO update.
$ git push --force
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
 + d14aaa0...7b2dc96 master -> master (forced update)

查看 提交历史,可以看到提交 d14aaa0 不存在。

If you want to edit a remote branch's history destructively (e.g. rebase/amend), make your changes locally and then do git push --force. Sometimes it does not work (repository administrators can disable this feature); in that case, you can try deleting the remote branch with git push origin :my_branch and then pushing it again with git push origin my_branch. Otherwise you can use git revert, which is the recommended way if you work in a team (the rule of thumb is that published history should not be modified).

Here's an example (using this Github repository):

$ touch SOMETHING
$ emacs SOMETHING 
$ git add SOMETHING 
$ git ci -m SOMETHING
[master d14aaa0] SOMETHING
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 SOMETHING
$ git push
Counting objects: 8, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 611 bytes, done.
Total 6 (delta 3), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
   53f836a..d14aaa0  master -> master
$ git reset --hard "HEAD~"
HEAD is now at 7b2dc96 TODO update.
$ git push --force
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
 + d14aaa0...7b2dc96 master -> master (forced update)

Looking at the commit history, you can see that commit d14aaa0 is absent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文