Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions aria/contents/docs/libra/command/revert/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: The [revert] Command
description: Create a new commit that reverts the changes of an existing commit
---

### Usage

libra revert [OPTIONS] <COMMIT>

### Arguments

- <COMMIT> - (Required) The commit to revert. Can be a commit hash, branch name, or a reference like HEAD.

### Description

Given one existing commit, this command creates a new commit that applies the inverse of the changes introduced by the specified commit. This effectively "undoes" the target commit.

Unlike libra reset, which alters the existing commit history, libra revert does not change the project history. Instead, it adds a new commit at the tip of the branch with the inverted content. This makes it a safe operation for reverting changes on a public or shared branch, as it preserves the original history.

By default, a new commit is created with a message indicating which commit was reverted.

This implementation does not support reverting merge commits. The command must be run from a branch, not a 'detached HEAD' state.

### Options

- -n, --no-commit
Performs the revert operation by applying the inverse changes to the working directory and index, but does not create a new commit. The changes will be staged, allowing you to inspect or modify them before committing manually.
- -h, --help
Print help
### Example
- libra revert HEAD~2

Creates a new commit that undoes the changes made two commits before the current HEAD.

- libra revert -n a1b2c3d4

Applies the inverse of the changes from commit a1b2c3d4 to the index, but does not commit them, leaving them staged.


<Note type="note" title="Note">
All parameters should align with Git’s behavior as closely as possible, but
there may be some differences. Refs https://git-scm.com/docs/git-branch for
more information.
</Note>
2 changes: 1 addition & 1 deletion ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl ApiHandler for MonoApiService {
})
.collect();
storage.batch_save_model(save_trees).await.unwrap();

Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion libra/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ enum Commands {
Pull(command::pull::PullArgs),
#[command(about = "Show different between files")]
Diff(command::diff::DiffArgs),

#[command(about = "Revert some existing commits")]
Revert(command::revert::RevertArgs),
#[command(subcommand, about = "Manage set of tracked repositories")]
Remote(command::remote::RemoteCmds),
#[command(about = "Manage repository configurations")]
Expand Down Expand Up @@ -125,6 +126,7 @@ pub async fn parse_async(args: Option<&[&str]>) -> Result<(), GitError> {
Commands::IndexPack(args) => command::index_pack::execute(args),
Commands::Fetch(args) => command::fetch::execute(args).await,
Commands::Diff(args) => command::diff::execute(args).await,
Commands::Revert(args) => command::revert::execute(args).await,
Commands::Remote(cmd) => command::remote::execute(cmd).await,
Commands::Pull(args) => command::pull::execute(args).await,
Commands::Config(args) => command::config::execute(args).await,
Expand Down
5 changes: 3 additions & 2 deletions libra/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod remote;
pub mod remove;
pub mod reset;
pub mod restore;
pub mod revert;
pub mod status;
pub mod switch;

Expand Down Expand Up @@ -46,13 +47,13 @@ where
}

// impl save for all objects
pub fn save_object<T>(object: &T, ojb_id: &SHA1) -> Result<(), GitError>
pub fn save_object<T>(object: &T, obj_id: &SHA1) -> Result<(), GitError>
where
T: ObjectTrait,
{
let storage = util::objects_storage();
let data = object.to_data()?;
storage.put(ojb_id, &data, object.get_type())?;
storage.put(obj_id, &data, object.get_type())?;
Ok(())
}

Expand Down
Loading
Loading