开发者

How to discard changes using repo

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

It would be开发者_JAVA技巧 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?


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


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


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


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.


repo forall does not cover all of the git tree

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜