2016-10-18 3 views
1

필자의 요구 사항은 https//:myproject.git과 같은 중앙 위치에있는 원격베이스 리포지토리에 프로그래밍 방식으로 파일을 커밋하고 싶습니다.JGit을 사용하여 원격베이스 리포지토리에 파일을 커밋 할 수 있습니까?

내 로컬 컴퓨터에 기본 저장소를 복제하지 않고 파일을 원격 저장소 (마스터)에 커밋 할 수 있는지 알고 싶습니다. 나는 JGit의 초보자입니다. 저에게 알려주세요.

+0

자식은 로컬 파일에서 작동 일부 기사를 보라 할 수 있습니다. 로컬 저장소와 원격 저장소간에 상태를 동기화하는 기능이 있지만 모든 저장소 업데이트는 로컬에서 수행됩니다. 저장소를 복제하고 변경 한 다음 다시 원격지로 푸시해야합니다. – larsks

답변

1

@larsks 이미 지적했듯이 원격 저장소의 로컬 복제본을 먼저 만들어야합니다. 변경 사항은 기본 저장소의 로컬 복사본에만 커밋 될 수 있습니다. 마지막으로 원래 저장소로 이동하면 다른 저장소에 대한 원격 저장소에서 로컬 변경 내용을 사용할 수있게됩니다.

JGit에는 Git 명령 줄을 모델로하여 복제, 커밋 및 푸시에 사용할 수있는 명령 API이 있습니다. 예를 들어

는 :

// clone base repository into a local directory 
Git git Git.cloneRepository().setURI("https://...").setDirectory(new File("/path/to/local/copy/of/repo")).call(); 
// create, modify, delete files in the repository's working directory, 
// that is located at git.getRepository().getWorkTree() 
// add and new and changed files to the staging area 
git.add().addFilepattern(".").call(); 
// remove deleted files from the staging area 
git.rm().addFilepattern("").call(); 
// commit changes to the local repository 
git.commit().setMessage("...").call(); 
// push new commits to the base repository 
git.push().setRemote("http://...").setRefspec(new Refspec("refs/heads/*:refs/remotes/origin/*")).call(); 

상기 실시 예에서 명시 적으로 업데이트하는 PushCommand 어느 지점에 푸시되는 원격 말한다. 대부분의 경우 setter를 생략하고 명령이 git.push().call() 인 저장소 구성에서 적절한 기본값을 읽도록하는 것으로 충분할 수 있습니다.

은 자세한 내용은, 당신은 authentication처럼 cloning, making local changes의 자세한 내용 및 기타 측면에 가서 setting up the development environment