.gitディレクトリ内のファイルからcommitを探索するやつ https://github.com/ukyo/git-miru-kun
$ npm i -g https://github.com/ukyo/git-miru-kun
$ cd path/to/repos
$ node hoge.js
まぁ、これ100%確実に発見できるわけではなくて、現実的には平気だろっていうレベルのやつです。
| const gmk = require('git-miru-kun'); | |
| (async () => { | |
| const gitDir = await gmk.readGitDir('.git'); | |
| const parentHashDict = {}; | |
| const targetBranch = await gitDir.readHead(); | |
| const { branchName } = targetBranch; | |
| const commits = (await gitDir.readBranches()) | |
| .filter(b => b.branchName !== branchName) | |
| .map(b => b.commit); | |
| let baseCommitHash; | |
| let x = 1; | |
| while (!baseCommitHash) { | |
| do { | |
| for (let i = commits.length - 1; i >= 0; i--) { | |
| let commit = commits[i]; | |
| for (let j = 0; j < 1000; j++) { | |
| const { parentHash } = commit; | |
| if (!commit.hasParent() || parentHashDict[parentHash]) { | |
| commits.splice(i, 1); | |
| break; | |
| } | |
| if (commit.isMergeCommit()) { | |
| commits.push(await commit.readMergedParent()); | |
| } | |
| parentHashDict[parentHash] = true; | |
| try { | |
| commit = await commit.readParent(); | |
| } catch (e) { | |
| commits.splice(i, 1); | |
| break; | |
| } | |
| } | |
| } | |
| } while (commits.length > 1); | |
| let { commit } = targetBranch; | |
| for (let i = 0, n = x * 16; i < n; i++) { | |
| console.log(commit.hash, commit.isMergeCommit()); | |
| if (commit.isMergeCommit()) { | |
| baseCommitHash = commit.hash; | |
| break; | |
| } | |
| if (parentHashDict[commit.parentHash]) { | |
| baseCommitHash = commit.parentHash; | |
| break; | |
| } | |
| commit = await commit.readParent(); | |
| } | |
| x++; | |
| } | |
| console.log('base commit hash is ', baseCommitHash); | |
| })(); |
.gitディレクトリ内のファイルからcommitを探索するやつ https://github.com/ukyo/git-miru-kun
$ npm i -g https://github.com/ukyo/git-miru-kun
$ cd path/to/repos
$ node hoge.js
まぁ、これ100%確実に発見できるわけではなくて、現実的には平気だろっていうレベルのやつです。