简体   繁体   中英

How to move a file programatically in a GitHub repository with Java?

I am using the org.eclipse.egit.github.core library (version 4.9.0.201710071750-r) and for the moment, I am able to push a list of files in a single commit.

I have for example packageA/myfile.xml and want to move it to packageB/myfile.xml .

I need to do it in a single commit and can be one of many operations (can be other new files, modified files).

The library of choice to programmatically manipulate Git repositories with Java is JGit, a pure Java implementation of Git.

In the context of your question, you would

  1. move the file in question through the Java NIO/File API

  2. remove the old file ( packageA/myfile.xml ) with the JGit RmCommand

  3. add the moved file ( packageB/myfile.xml ) to the index with JGit's AddCommand

  4. commit the moved (actually removed and then (re-) added) file

The org.eclipse.egit.github.core plug-in/library that you mentioned is intended to interact with GitHub's REST API. It is used as the basis for the GitHub Eclipse integration, to access and query Git repositories hosted on GitHub review pul requests and similar things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM