Cristiano
Cristiano

Reputation: 876

GIT how to reset without a commit

Suppose that I create an empty GIT repo with the following command:

# git init

Then I start adding remote repositories:

# git remote add remote1 ........
# git remote add remote2 ........
# git remote add remote3 ........

and fetching:

# git fetch --all

Finally, I merge into my local repo all the remote branches that I need:

# git merge remote1/branchX
# git merge remote2/branchY
# git merge remote3/branchZ

Now, suppose I have to reset my local repo at before all the merges; the natural solution seems to be to just create a new empty repository. But the problem is: the fetch of my remote repositories takes a very long time (hours), so I would like to avoid to re-fecth all again.

I cannot do a "git reset" because I do not have a commit preceeding all the merges.

Upvotes: 2

Views: 229

Answers (2)

Matt Enright
Matt Enright

Reputation: 7484

A decent way to cheat this is to do a git init && git commit --allow-empty -m 'Initial commit.' when you set up the repository, which alleviates the symptom of a non-existent HEAD at least.

But since you've fetched all of the remotes already, you do not need to blow away the repository in order to create a new empty/unrelated branch if that's more what you're looking for:

git symbolic-ref HEAD refs/heads/new-branch

Then when you commit/merge whatever on HEAD, git will fill in the new branch for you. Once you have another existing branch you can hard reset master or do whatever other tricks you'd like to juggle them around.

Upvotes: 3

wemu
wemu

Reputation: 8160

I think this thread: Checkout old commit and make it a new commit gives some possibilities. Either checkout one of the previous commits before the merges or reset to that point. If mutliple commits took place I would first lookup the SHA value prior to the merges and use that one.

Upvotes: 0

Related Questions