How to discard changes using repo

ResetRepo

Reset Problem Overview


repo status shows me a lot of un-wanted changes.

It would be duplicated if I enter every project and use git reset --hard.

Is there a way to reset all the changes using repo, something like repo reset --hard?

Reset Solutions


Solution 1 - Reset

This is the command I use for this kind of things, very useful

repo forall -vc "git reset --hard"

What everything mean here ?

the repo forall will execute for all repos.

the -v is verbose, so it will print the output of the command

the -c "COMMAND TO EXECUTE" is the actual command you want

Solution 2 - Reset

If there is a need to revert working folder to the clean state where you don't have local modifications and no untracked files (i.e. where repo status shows nothing), I found these two approaches useful on repo sync and deleted/modified files

repo forall -c 'git reset --hard ; git clean -fdx' 

or

rm -rf * ; repo sync -l
// note that .repo is preserved after that

Note, that this is not equivalent to initializing a new local repo and syncing (e.g. stash is preserved)

If you are not sure what is going on, please read the full thread repo sync and deleted/modified files

Solution 3 - Reset

You can use the repo command as the following to revert all your changes:

repo sync -d

This will revert all your changes back to original revision.

Edited:

The command above is working only with the version at that time.

The working command is :

repo forall -vc "git reset --hard"

The command and options description

  • forall

> Executes the given shell command in each project

Options (that can be used with the forall command) >-c: command and arguments to execute. The command is evaluated through /bin/sh and any arguments after it are passed through as shell > positional parameters. > >-p: show project headers before output of the specified command. This is achieved by binding pipes to the command's stdin, stdout, and > sterr streams, and piping all output into a continuous stream that is > displayed in a single pager session. > >-v: show messages the command writes to stderr.

For more information please refer the repo document

Solution 4 - Reset

I use the repo forall command with the below syntax and it helps me to reset the tracking files.

repo forall -p -c 'git checkout -f foo'

where foo should be replaced with a legitimate branch name.

Solution 5 - Reset

#!/bin/bash
for gitdir in $(find . -name .git); do
    pushd $(dirname $gitdir)
    git reset --hard
    popd
done

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohnnyView Question on Stackoverflow
Solution 1 - ResetstdcallView Answer on Stackoverflow
Solution 2 - ResetpmodView Answer on Stackoverflow
Solution 3 - ResetShantha KumaraView Answer on Stackoverflow
Solution 4 - ResetransView Answer on Stackoverflow
Solution 5 - Reseth0tw1r3View Answer on Stackoverflow