An Capone
An Capone

Reputation: 131

Netbeans git reset

i found myself in trouble with git these days.

I am working on some major changes in one of webs i am developing.

There are two versions, one publicly accesible and one accesible from local net, which is done by two git branches. Lets call them "master" and "dev".

All the work i do with git is done by netbeans git functionality.

There are 3 repositories, one on my local computer, and two remote repos on VPS, one for master and one for dev.

Recently i have been doing some work that now apperars to be unnecessary, more likely harmful, so i figured out i need to roll back these changes. They all were done on "dev", so i have the original state saved in "master", i tried simply merging master into dev, but the result was disappointing, files, that were modified in dev stayed modified. That is when i figured out i had to use git reset, which seemed to be working quite fine for my local repo, but when i tried to push to remote repo, it detected, that there are new commits and applied them, which lead to the exact same state as when i began. To be specific, it first forced me to pull commits from remotes, merge them and then do whatever else. How do i prevent this behavior? In the best this should be done using strictly Netbeans git functionality, but if that would be not possible i am open to command line solutions as well.

So to be clear, my question is:

After git reset in local repo, how do i prevent further commits from reapplying to HEAD? If possible this should be done using only Netbeans git functionality.

Upvotes: 0

Views: 569

Answers (1)

asbachb
asbachb

Reputation: 573

Normally you could do a git push --force. This push syncs every reference in you local branch with the remote references even if the commits you try to push does not match with the remote ones.

WARNING: Be careful with --forced option. When you're working in a team and you don't know what you're exactly doing this can get into a real pain.

As far as I know NetBeans does not support git push --force via ui.

But when you want to learn git right you should have a look at the cli. It's OS and development tool independent and you can use the full spectrum of git commands.

Another solution might be to use an entire branch for your features. If the feature dies just delete the branch. No revert. No resets at all.

EDIT1:

so i need to set "dev" (both local and remote) to the exact same state as "master"

ASSUMPTION: I assume that your remotes' location name is origin

  • git fetch --all (get's all reference of you remote locations)
  • git checkout dev
  • git reset --hard origin/master (resets your local dev branch to the remote version of master)
  • git push -u origin dev -f (overwrites the remote dev branch with your local version)

Upvotes: 1

Related Questions