简体   繁体   中英

Reflection on remote GitHub repository

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!

PS 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM