Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse a git fetch

Tags:

I have a thorough understanding of git, and the difference between pull, fetch, and merge. I have a remote that I track, fetch, and merge with occasionally, let say it's origin/master. What I'm looking to do is reverse the behavior of a 'git fetch'. It sounds goofy, but I want to un-update where my remote tracking branch points, to an older state, the state right before the last fetch. Is this possible?

For example, lets say this is my workflow...

git show origin/master # shows commit abc123  git fetch              # yay i got something!  git show origin/master # shows commit def456 

mystery command goes here so that...

git show origin/master # shows commit abc123 

It's kind of a weird thing to want, but I have a crontab that watches a git repo to detect when there's something to fetch, and I'm having issues debugging the script that performs some actions based on this behavior. Instead of waiting for origin/master to change, I'd like to change it myself so I can debug my script!

like image 492
user2141094 Avatar asked Mar 06 '13 17:03

user2141094


People also ask

Can I undo a git fetch?

There is no command to explicitly undo the git pull command. The alternative is to use git reset, which reverts a repository back to a previous commit.

How do I revert a pull in git conflict?

In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.


1 Answers

You want

git update-ref refs/remotes/origin/master refs/remotes/origin/master@{1}

update-ref wants the full spell on the ref it's updating because it's (much) lower level than the commands that respect ref-naming conventions.

like image 125
jthill Avatar answered Oct 18 '22 08:10

jthill