5

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

HelloCW
  • 843
  • 22
  • 125
  • 310
  • Do you want to have 'click' option for this actions or can you just use built-in console? – dunajski Mar 01 '19 at 09:32
  • Thanks! I hope to have a 'click' or just like 'check box' option for force push. – HelloCW Mar 01 '19 at 09:36
  • Here is solution if you have closed terminal/console https://stackoverflow.com/a/32245083/10921202 and then you can type your desired actions – dunajski Mar 01 '19 at 09:45
  • As I found in internet in Android Studio force push is disabled by default. Could you check VCS/Git/Push in options? Right now I don't have acces to my Android Studio. – dunajski Mar 01 '19 at 10:02
  • https://i.stack.imgur.com/ps9Bd.jpg there is foto with this option in background – dunajski Mar 01 '19 at 10:12

1 Answers1

13
  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.
Geno Chen
  • 4,916
  • 6
  • 21
  • 39