question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

So now from #129 I have function that restore git repo from HEAD~1 but when I have pushed the commit I to update remote I need to use git push -f.

if this is how push works every time then I need to a way to check if push will overwrite commits so I would be able to reject it when user don’t use force.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wmhiltoncommented, Jul 22, 2018

🎉 This issue has been resolved in version 0.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
wmhiltoncommented, Jul 21, 2018

A deep search of the git source code reveals that git push -f is a client side implementation detail. So yes, we must check that what we are pushing follows the 4 rules laid out in the comment ourselves before doing a push:


		/*
		 * If the update isn't already rejected then check
		 * the usual "must fast-forward" rules.
		 *
		 * Decide whether an individual refspec A:B can be
		 * pushed.  The push will succeed if any of the
		 * following are true:
		 *
		 * (1) the remote reference B does not exist
		 *
		 * (2) the remote reference B is being removed (i.e.,
		 *     pushing :B where no source is specified)
		 *
		 * (3) the destination is not under refs/tags/, and
		 *     if the old and new value is a commit, the new
		 *     is a descendant of the old.
		 *
		 * (4) it is forced using the +A:B notation, or by
		 *     passing the --force argument
		 */

which, written another way, I think ends up being:

Require --force for a push if:

  • the ref is a tag that already exists on the server
  • the ref is a branch that already exists on the server and the new oid is NOT a descendent of the old
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I properly force a Git push? - Stack Overflow
git push --force overwrites the remote branch, while git push --force-with-lease only overwrites the remote branch if your local copy is aware ...
Read more >
How to force push in Git | Learn Version Control with Git
The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with...
Read more >
git-push Documentation - Git
To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master...
Read more >
What is the git push --force -u origin command? - Educative.io
The git push --force -u origin command uploads content from a local repository to a remote repository. Normally, Git only allows changes to...
Read more >
git push --force and how to deal with it - Evil Martians
GitHub and GitLab have a feature called “protected branches.” We can mark master , develop , stable , or any other crucial branches...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found