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

本文介绍了如何使用GitHub for Windows添加并提交代码库。通过简单的拖拽操作即可将现有代码库导入到GitHub账户,并解决了初次提交失败的问题。文章还提供了通过PowerShell手动提交文件的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值