HelloCW
HelloCW

Reputation: 2295

How can I force push to remote repository in GitHub in Android Studio 3.3.1?

I use Github for my project in Android Studio 3.3.1 I use the following code to return to a point both local repository and remote repository.

The line 1 can be launched in Android Studio 3.3.1 IDE.

  1. Can the line 2 be launched in Android Studio 3.3.1 IDE ? If so, how can I do?

  2. And more, does it mean the content of will overwrite the content of remote without merger when I use force parameter to push ?

Code

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

To Geno Chen: Thanks!

But Force Push is disabled, you can see the following image. I use Android Studio 3.3.1 in Windows 10 OS.

Image enter image description here

Upvotes: 6

Views: 8133

Answers (1)

Geno Chen
Geno Chen

Reputation: 5214

  1. Yes, you can. Just use the small drop-down menu in "Push Commits" window, elevated from VCS -> Git -> Push... or Ctrl+Shift+K.

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

  1. Yes, use --force with git push will overwrite the remote repository with local, without a merger, and can cause the remote repository to lose commits; use it with care. You may need to do a git pull first, or use a "safer" --force-with-lease.

Update:

  1. Protected branches, listed in File -> Settings -> Version Control -> Git, is not allowed to do a force push. So you have to choose another branch rather than master to do a force push, or remove settings of protected branches.

Upvotes: 18

Related Questions