github存在错误的未commit文件

今天在项目里,添加了一个.png文件,后来发现没用,又给手动删除了。但是在commit的时候却还有这个文件,标注是A,也就是新增加的。discard changes也不管用。

提示:This operation cannot be undone

后来在命令行里,进入工程目录。然后git commit -a -m "commit error file"。希望通过命令强制commit。但是结果是:nothing to commit (working directory clean)。

最后直接在项目里随便做几个改动,再git commit -a -m "commit error file",就ok了。

不知道为什么会这样!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要修改GitHub上的文件,您需要使用GitHub API。以下是一个简单的Java代码片段,用于更新GitHub上的文件。 ```java import org.apache.commons.codec.binary.Base64; import org.eclipse.egit.github.core.Commit; import org.eclipse.egit.github.core.CommitUser; import org.eclipse.egit.github.core.RepositoryContents; import org.eclipse.egit.github.core.service.ContentsService; import org.eclipse.egit.github.core.service.RepositoryService; import java.io.IOException; public class UpdateGitHubFile { private static final String USERNAME = "YourGitHubUsername"; private static final String PASSWORD = "YourGitHubPassword"; private static final String REPO_OWNER = "RepositoryOwner"; private static final String REPO_NAME = "RepositoryName"; private static final String FILE_PATH = "FilePath"; private static final String COMMIT_MESSAGE = "CommitMessage"; private static final String NEW_CONTENT = "NewContent"; public static void main(String[] args) throws IOException { RepositoryService service = new RepositoryService(); service.getClient().setCredentials(USERNAME, PASSWORD); ContentsService contentsService = new ContentsService(); contentsService.getClient().setCredentials(USERNAME, PASSWORD); RepositoryContents contents = contentsService.getContents(REPO_OWNER, REPO_NAME, FILE_PATH, null); String sha = contents.getSha(); Commit commit = new Commit(); commit.setMessage(COMMIT_MESSAGE); CommitUser author = new CommitUser(); author.setName("YourName"); author.setEmail("YourEmail"); commit.setAuthor(author); String encodedContent = Base64.encodeBase64String(NEW_CONTENT.getBytes()); contents.setContent(encodedContent); contentsService.updateContents(REPO_OWNER, REPO_NAME, FILE_PATH, contents, sha, commit); } } ``` 请注意,您需要使用您自己的GitHub用户名和密码来进行身份验证。此代码仅用于演示目的,实际代码需要更加严密的错误处理和身份验证方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值