Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

ALL,

I unfortunately had to perform git reset --hard to rollback to the revision I need on my local repository. That means that all commits between the old HEAD and the revision I am resetting to will be gone.

Now if I do git push --force will the same happens on the remote GitHub repository? And how do I preserve the same deletion on another machine?

Basically I want a remote GitHub repository to look exactly the same as the local repository - all commits in between removed, and also all other machines where this repository resides deletes those commits.

Or I shouldn't be doing git reset and need another command instead?

TIA!

P.S. As a sole developer on the code, I don't care about other people. So,

git push --force
git pull (on another machine)

is the right thing to do in order to remove commits both on remote and another machine?

question from:https://stackoverflow.com/questions/65651143/reflection-on-remote-github-repository

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
247 views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, if you do git push --force the remote will look like your local repository. However as a best practice you should do it like this:

git push --force-with-lease
git pull --rebase

--force-with-lease is a safety measure to prevent you from pushing if the remote branch is newer than your branch. Imagine that in the time after you’ve pulled and while you did your git reset, a new commit was pushed to the repository. That would be overwritten with --force but not with --force-with-lease.

Even if you are working alone on your repository, you might have pushed on another machine and forgot about it when you did your force push.

git pull --rebase should be the default way of pulling. Any alteration to history will be correctly applied. And if you have local commits, they will be stacked on top of the history.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...