Github for Windows:Commit failed: Failed to create a new commit

Github for Windows添加库十分简单,以京东代码库为例,只要选中“代码库首页”的URL(如https://code.jd.com/mawenjian/jae_appname),将其拖入Github for Windows窗口,待下面显示“drop anywhere to clone”松手即可。而后,输入用户名和密码,就开始导入代码了。

官方说明如下:

You can add any repository already on your hard drive by dragging a folder in from Explorer. If that folder is a Git repository, GitHub for Windows will import all of the history and connect it to your GitHub accounts.

至于提交代码,也很简单,待修改完成后添加注释,再选择“Commit”提交即可。不过我第一次提交代码时,GfW竟然提示“Commit failed:Failed to create a new commit”错误,我还以为这货有BUG呢。

好在我从StackOverflow找到了解决方案:

1.打开PowerShell窗口,输入 “git add [file name]” 命令提交文件;

2.输入”git status”命令,查看那些文件被提交,其中绿色标记是提交成功的,红色标记是没有提交成功的;

3.当所有文件都被提交后,输入”git commit”命令。

到了这里,我遇到的问题提示是没有配置用户名和邮箱(大概这个意思)。然后我按照提示配置好用户名和邮箱,再提交代码就没有问题了。

StackOverflow英文解释如下:

Try opening up PowerShell and manually committing each file using the “git add [file name]” command. To see which files have been committed, enter “git status” into the command line. The green files have been committed, the red ones uncommitted.

Once you’ve committed them all, type “git commit.” Then go back to Github for Windows and sync it up.

I’m not sure what causes this issue, but once I followed the above steps, Github went back to its normal, awesome behavior.

你可能感兴趣的:(github,windows,commit,failed)