简体   繁体   中英

way to combine all commits into a single commit using libgit2

I want to combine all commits into one for removes the history. I know that it's possible in Git command line, but I did not found a way in libgit2 yet.

I'm using libgit2 in the latest version, compiled by me in C++.

What do you suggest?

There are a few ways to think about this. On the command line you might do something like this:

git reset --soft <some-ancestor-commit-ish>
git commit -m "This commit combines some history."

The soft reset moves the current branch to point to some ancestor commit without changing the working directory and index. So now you have all of the changes introduced by those commits staged and you can commit them as a new combined commit. Those two steps can be translated directly to libgit2 with something like:

git_reset(repo, ancestor_commit, GIT_RESET_SOFT, NULL);
git_commit_create(...);

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