如何在Android Studio 3.3.1中强制推送到GitHub中的远程存储库?

时间:2019-03-01 09:12:42

标签: git android-studio github

我在Android Studio 3.3.1中将Github用于我的项目 我使用以下代码返回本地存储库和远程存储库。

第1行可以在Android Studio 3.3.1 IDE中启动。

  1. 第2行可以在Android Studio 3.3.1 IDE中启动吗?如果可以,该怎么办?

  2. 还有,这是否意味着当我使用 force 参数进行推送时,内容会覆盖远程内容而不进行合并吗?

代码

git reset --hard <commit_hash>
git push origin <branch_name> --force

对Geno Chen:谢谢!

但是“强制推送”已禁用,您可以看到下图。我在Windows 10操作系统中使用Android Studio 3.3.1。

图片 enter image description here

1 个答案:

答案 0 :(得分:1)

  1. 是的,可以。只需使用“推送提交”窗口中的小下拉菜单,从VCS-> Git-> Push... Ctrl + Shift + K

a "&Force Push" button in the drop-down menu

  1. 是的,将--forcegit push一起使用将覆盖本地的远程存储库,而不会合并and can cause the remote repository to lose commits; use it with care。您可能需要先进行git pulluse a "safer" --force-with-lease

更新

    Protected branches-> File-> Settings-> Version Control中列出的
  1. Git不允许强行推入。因此,您必须选择另一个分支而不是master来进行强制推送,或删除受保护分支的设置。