git-在致命消息后继续
解决合并冲突后,我已将文件添加到暂存区。然后我不小心执行了一个带有修改选项的提交命令:
git commit --amend --no-edit
我收到以下消息:
fatal: You are in the middle of a merge -- cannot amend.
这是否意味着根本没有执行提交命令?我可以继续使用正确的命令吗?:
git commit --no-edit
回答
错误消息“您正在合并 - 无法修改。” 由函数生成的parse_and_validate_options()是通过函数调用cmd_commit() 之前它开始实际工作。
commit命令代码的相关部分如下所示:
...
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_commit_usage, builtin_commit_options);
status_init_config(&s, git_commit_config);
s.commit_template = 1;
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
if (get_oid("HEAD", &oid))
current_head = NULL;
else {
current_head = lookup_commit_or_die(&oid, "HEAD");
if (parse_commit(current_head))
die(_("could not parse HEAD commit"));
}
verbose = -1; /* unspecified */
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
builtin_commit_usage,
prefix, current_head, &s);
if (verbose == -1)
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
if (dry_run)
return dry_run_commit(argv, prefix, current_head, &s);
index_file = prepare_index(argv, prefix, current_head, 0);
/* Set up everything for writing the commit object. This includes
running hooks, writing the trees, and interacting with the user. */
if (!prepare_to_commit(index_file, prefix,
current_head, &s, &author_ident)) {
rollback_index_files();
return 1;
}
...
在index_file = prepare_index(argv, prefix, current_head, 0)代码没有更改任何内容的行之前,它验证命令行参数并标识所需的对象(当前提交)。
您错误运行的命令没有更改存储库中的任何内容。Git 中实施的安全措施可防止它破坏您的工作。您可以安全地运行正确的命令来结束合并。