git rebase 后找回消失的commit

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/whereismatrix/article/details/50611706

git rebase 后找回消失的commit

在git rebase操作时,存在冲突时,使用git rebase --abort处理后,结果发现commit的修改和记录都没有了。(使用git rebase --skip处理,也有导致commit消失不见得情况),就是使用git log看不到。


并不是真的在git中完全消失了。


这是可以使用reflog命令列出log 信息。
reflog : reference logs

$ git reflog 
d185b35 HEAD@{0}: rebase finished: returning to refs/heads/passport
d185b35 HEAD@{1}: rebase: checkout origin/passport
4ab8e52 HEAD@{2}: checkout: moving from passport_email to passport
d185b35 HEAD@{3}: checkout: moving from passport to passport_email
4ab8e52 HEAD@{4}: checkout: moving from passprot_bak to passport
d185b35 HEAD@{5}: checkout: moving from passport to passprot_bak
4ab8e52 HEAD@{6}: checkout: moving from passprot_bak to passport
d185b35 HEAD@{7}: commit: 添加邮件发送处理操作
............

这里显示了commit 的sha, version, message,找到你消失的commit,然后可以使用这个‘消失的’commit重新建立一个branch.

$git checkout -b branch-bak [commit-sha]

然后可以出来冲突,再git add, git commit, git push等操作,把修改提交。

最后,看看git help

NAME
       git-reflog - Manage reflog information

SYNOPSIS
       git reflog <subcommand> <options>

DESCRIPTION
       The command takes various subcommands, and different options depending on the subcommand:

           git reflog [show] [log-options] [<ref>]
           git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                   [--rewrite] [--updateref] [--stale-fix]
                   [--dry-run] [--verbose] [--all | <refs>...]
           git reflog delete [--rewrite] [--updateref]
                   [--dry-run] [--verbose] ref@{specifier}...

       Reference logs, or "reflogs", record when the tips of branches and other references were updated in the local
       repository. Reflogs are useful in various Git commands, to specify the old value of a reference. For example,
       HEAD@{2} means "where HEAD used to be two moves ago", master@{one.week.ago} means "where master used to point to
       one week ago in this local repository", and so on. See gitrevisions(7) for more details.

       This command manages the information recorded in the reflogs.

       The "show" subcommand (which is also the default, in the absence of any subcommands) shows the log of the
       reference provided in the command-line (or HEAD, by default). The reflog covers all recent actions, and in
       addition the HEAD reflog records branch switching. git reflog show is an alias for git log -g --abbrev-commit
       --pretty=oneline; see git-log(1) for more information.

       The "expire" subcommand prunes older reflog entries. Entries older than expire time, or entries older than
       expire-unreachable time and not reachable from the current tip, are removed from the reflog. This is typically
       not used directly by end users -- instead, see git-gc(1).

       The "delete" subcommand deletes single entries from the reflog. Its argument must be an exact entry (e.g. "git
       reflog delete master@{2}"). This subcommand is also typically not used directly by end users.

OPTIONS
   Options for show
       git reflog show accepts any of the options accepted by git log.

   Options for expire
       --all
           Process the reflogs of all references.

       --expire=<time>
           Prune entries older than the specified time. If this option is not specified, the expiration time is taken
           from the configuration setting gc.reflogExpire, which in turn defaults to 90 days.  --expire=all prunes
           entries regardless of their age; --expire=never turns off pruning of reachable entries (but see
           --expire-unreachable).

       --expire-unreachable=<time>
           Prune entries older than <time> that are not reachable from the current tip of the branch. If this option is
           not specified, the expiration time is taken from the configuration setting gc.reflogExpireUnreachable, which
           in turn defaults to 30 days.  --expire-unreachable=all prunes unreachable entries regardless of their age;
           --expire-unreachable=never turns off early pruning of unreachable entries (but see --expire).

       --updateref
           Update the reference to the value of the top reflog entry (i.e. <ref>@{0}) if the previous top entry was
           pruned. (This option is ignored for symbolic references.)
           …………
展开阅读全文

没有更多推荐了,返回首页