The repository exists, but all my commits have disappeared.
What exactly do you mean?
Is the working tree still there?
Does .git/
exist?
Are there any files in it?
The messages you posted suggest that the file .git/HEAD
does not exist.
It defines the expected state of the working tree (what you had checked out).
If that file is gone, git doesn't know where you were.
You could try creating the file yourself, with this content:
ref: refs/heads/master
If you were on a different branch, just replace "master" with the branch name.
If you were not on a branch, it would be more complicated.
.git/logs/HEAD
records past states of HEAD, with later lines at the bottom.
This example line shows a checkout:
25f2a6099fb5f9f2192a510c42f704f9fc4bcecb 65abb1a3dc102e2498860f01fb179cda4c51decb Rainer Blome <rainer.blome@wherever.you.are.com> 1346938344 +0200 checkout: moving from master to MySuperBranch
The SHA1s in front refer to commits.
You ought to be able to find these in the branch log,
for example .git/logs/refs/heads/master
.
The git reflog output you gave looks like refs/heads/master
is missing as well.
Its sole content is supposed to be the SHA1 of the latest commit on it (and a newline).
You can find the latest SHA1 at the end of the branch log,
for example .git/logs/refs/heads/master
.
If you're going to use positional parameters in git aliases, be sure to specify sh -c
. The following worked for me locally:
ff = !sh -c 'git checkout master && git merge "$1" && git checkout "$1"' -
(dead link)
The "why" relates to the way git parses the alias commands and is summed up in this gmane thread.
The -
at the end of the command signals sh
that option processing is finished. From man sh
:
A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.
If it weren't present, it would introduce a bug in the alias, by treating $1
as an option on the sh
command instead of as a positional argument. Consider this trivial example:
$ sh -c 'echo $1' foo # equivalent to 'echo' without argument
$ sh -c 'echo $1' - foo # will pass 'foo' to the string as $1
foo
In the first case, 'foo' was consumed by sh
as an option. In the second, it's correctly interpreted as $1
on the string.
Best Answer
If you want all changes from
master
indev_branch
, then:This only works if other people haven't cloned the repository.
If you have
dev_branch
pushed to a remote already, you have to do:To force-push to the remote. Warning: This will break the history of the branch for people who cloned it before! Then, other people will have to do a
git pull --rebase
on thedev_branch
to get the changes.You can also rename the dev branch to something old and then make a new branch from
master
with the same name:Or, use the
ours
strategy — not sure why it wouldn't work for you: