Clean reset hard, git pull
If I am wanting to do the git equivelent of:
git clean -fd
git reset --hard
git pull origin master
Whats the git2go equivelent? i cant seem to find how to set those flags in the documentation. I think I might not be able to do a pull, but a fetch and then a merge, but not sure about the resetting the current state
this seems overly hard to do? If I want to make sure that the git repository is always matching the github repository, then the above commands would be what I would do manually. I understand that each of the above don't have mapped commands in git2go, but I can't work out what the equivelent would be.
Could you give me a bit of a hand with this. I have still not worked it out entirely. Ive got to here:
func Pull(source string, dest string) error {
repo, err:= git.OpenRepository(dest)
remote, err:= repo.LookupRemote("origin")
log.Println(repo)
cbs := &git.RemoteCallbacks{
CredentialsCallback: credentialsCallback,
CertificateCheckCallback: certificateCheckCallback,
}
err = remote.SetCallbacks(cbs)
err = remote.Fetch([]string{}, "")
log.Println("fetch error: ", err)
remote_master, err := repo.LookupReference("refs/remotes/origin/master")
mergeRemoteHead, err := repo.AnnotatedCommitFromRef(remote_master)
mergeHeads := make([]*git.AnnotatedCommit, 1)
mergeHeads[0] = mergeRemoteHead
err = repo.Merge(mergeHeads, nil, nil)
log.Println("err: ", err)
repo.StateCleanup()
return err
}
What I am trying to do is the git2go equivelent of
git checkout master
git clean -fd
git reset --hard
git pull
I dont want any local changes to be kept. I think i am not too far. Everything seems to work, except that the files dont change to that on the server....
Where does a server come into this? Git operations are local, you're only ever doing local operations. Furthermore, what you're asking git2go to do here is perform a merge, which is very different from what you say you want to do.
If you want to checkout the files as the are on origin's master, then you can fetch and then use CheckoutTree() and pass it the tree of refs/remotes/origin/master's commit. You can then set the index to that with its ReadTree() and Write(), and then end with setting the current branch via SetHead().
This are the steps of git fetch origin && git reset --hard origin/master which is what your intent suggets. Your git commands use git pull which does not guarantee that you're overwriting anything, but is rather explicitly asking to merge in whatever local changes you have.
if it was me I prefer ‘git rebase —preserve=merges origin/master’ in case your side and remote has an commit you dont have on your side that you changed or did not change at or before the time you made the commit. Allowing to rewind back to common commits from origin/master, pull, and then reapplies your commit or commits individually. and avoids git push conflicts later on and seemingly works 99.9% of cases involving merge conflicts (also I hate the annoying ‘merge branch ‘%s’ into branch ‘%s’’ noise and wasteful commit history that makes it not linear and preserves branch names forever which is not what I want or like).
In my case, I'm trying to deploy code across servers using git where accident file changes needs to be ignored and not merged.