How to undo bzr add - bazaar

Sometimes I type bzr add and don't notice that I am not in the root of the branch but an ignored sub-folder. This then adds all files in that folders - often it is a build folder, with lots of files. Hence the question: how to undo a bzr add.

There is built-in way without need of xargs: bzr remove --new --keep

This answer is shamelessly stolen from here to make it more accessible (to me as well).
This will undo an erroneous bzr add:
bzr added -0 | xargs -0 bzr rm --keep

Related

See files affected by previous commits in bzr

When using bazaar you can easily see uncommited changes with the bzr diff command. You can also see changes since a specific revision, or use bzr status to see the filenames only.
bzr diff -c 2169
bzr status -c 2169
Instead of looking for a specific commit number, using bzr log is there a simple way to look at all changes in a number of commits, the previous 2 commits for example?
You can view log of the previous 2 commits like this:
bzr log -l2
You can view all the logs from a specific revision until the end with:
bzr log -r2169..
You can of course specify an end range as well.
You might also find useful some interesting revision specifiers for example last:N. You can view the diff or status of the last 2 revisions with:
bzr diff -rlast:3
bzr status -rlast:3
You can read more about revision specifiers in bzr help revisionspec.
Let me know if you were looking for something else.
You can do this using verbose. With --verbose (-v), bzr log will print all affected paths.
To get the files affected only in last commit, use
bzr log --verbose -l1
To get the files affected is level of commits, use
bzr log --verbose -l<level-of-commit>
To get the files affected in specific commit
bzr log --verbose -r<rev-of-commit>
you can use either flag --verbose or --v

How to retrieve branch whose tree has been removed and deleted?

I have a bazaar repository holding several branches. I recently removed one of the trees with bzr remove-tree path/to/branch followed by rm -r path/to/branch. Now if I understand correctly, the repository should still hold the branch history, since I never did bzr remove-branch. However, I can't figure out how to retrieve the branch to continue working on it. Can someone help?
You can use bzr heads --dead to see the heads (= most recent revisions) of deleted branches, including their global revision ids.
You can then do:
bzr branch -r REVISION_ID REPO_DIR BRANCH_DIR
Here, REVISION_ID is the id of the head that you want to restore, REPO_DIR is the directory that holds the repository, and BRANCH_DIR is the directory where you want the branch to be stored.
Edit: If the above doesn't work for some reason, you can also do:
bzr init BRANCH_DIR
cd BRANCH_DIR
bzr pull -r REVISION_ID .
BRANCH_DIR must be underneath the repository directory, of course.

Recreating a bazaar repository while only retaining a few of the branches

(EDIT: Removed my question, leaving a link to the question that confused me, because there's some useful stuff in some of the comments here)
The question here confused me, but was actually answered fully. That question asked how to build a new repository with only a few of the branches of the original repository.
I'm not entirely sure from your post what you're looking for. I'm taking a stab at giving an answer; let me know if that's not what you need.
The following is a simple script to copy all branches from a source to a target repo. Note that it won't work if the branch directory names contain any whitespace. You will have to setup the target repository with bzr init-repo first.
#!/bin/sh
SOURCEREPO=$1
TARGETREPO=$2
if [ ! -d "$TARGETREPO/.bzr" ]; then
echo "$TARGETREPO is not a Bazaar repository; create one with bzr init-repo"
exit 1
fi
BRANCHES=`cd "$SOURCEREPO"; find * -name .bzr -exec dirname '{}' ';'`
for branch in $BRANCHES; do
mkdir -p "$TARGETREPO/$branch"
if [ ! -d "$TARGETREPO/$branch/.bzr" ]; then
echo "Cloning $branch"
bzr branch --use-existing-dir "$SOURCEREPO/$branch" "$TARGETREPO/$branch" \
&& bzr config -d "$TARGETREPO/$branch" --remove parent_location
else
echo "Existing branch in $TARGETREPO/$branch"
fi
done
Basically, it does a bzr branch sourcerepo/branchdir targetrepo/branchdir for all branches and then uses bzr config to get rid of the parent location setting for each copy of a branch (because that location will presumably soon disappear).
I'm not quite sure what you really want here. Adding a remote branch to your local repository and recreating a repository from another are completely different things. The linked question is about the second, and the answers are spot-on, so I will address what you originally intended to do.
First of all, it's confusing when you say "main trunk repository", because "trunk" typically means a "main branch", and branches and repositories are different concepts, so "trunk repository" doesn't really make sense.
It seems to me that you have a shared repository: a container directory for multiple branches. For the sake of clarity: you create a shared repository with the command bzr init-repo, and you create branches in it with bzr init (new empty branch), or with bzr branch (copy of another branch, local or not).
Let's say you have a shared repository organized like this:
└── /tmp/shared/repo
   ├── bugfix123
   ├── feature1
   └── feature2
If you want to add remote branches of your teammates, you can do it with:
bzr branch url_of_remote_branch /tmp/shared/repo/somename
For example if your teammate has a branch at the url lp:~jack/proj/bugfix312 you could get it into your local repository with:
bzr branch lp:~jack/proj/bugfix312 /tmp/shared/repo/bugfix312
If later you decide you don't want to merge this branch, you can get rid of it with the commands:
bzr remove-branch /tmp/shared/repo/bugfix312
rm -fr /tmp/shared/repo/bugfix312
The first command only removes Bazaar's branch data, it keeps the directory intact. The second removes the working directory itself.
Let me know if you are looking for something else.

Forcedly update workspace in Accurev

Is there any command to update my workspace forcedly in Accurev, directly replace the local files with the backed files, and don't care about the conflict files, modified files and so on?
I really miss the cvs command cvs update -C -d
According to question, I have similar issues. Usually I just use following commands:
accurev update -9
accurev pop -O -R .
accurev update
No, you will need to run a few operations. You can create a script to force update your workspace.
Basically, you will generate a list of all the modified, kept, overlap, member files, then purge those files, then update your workspace.
Check out the stat section in the CLI manual.
What You can do is delete all the local files from the file system and then do a:
accurev pop -R <path to local workspace directory>
I had similar issue; First take a back up of existing workspace, then Delete all the files in the local work-space folder. Click update button on Accurev. All files will be re-loaded on the workspace.
If you just want to undo all changes you have done in the workspace:
accurev stat -R -m -fl . | xargs -n 1 accurev purge
You can use similar command with rm / accurev pop to force refetch from backend. You can also vary the flags, -m for modified, -k for kept, -a for all.

bzr - create tgz file containing full repository

I'm trying to backup my shared bzr repository. I have looked at bzr export hotcopy.tgz but it seems only to take a snapshot of the latest revision.
Is there a command for doing backups, or do I have to
full checkout into a tmp dir
compress the tmp dir
remove the tmp dir
Or is there a better way to backup a bzr repository?
You could try something like this:
mkdir /tmp/emptyrepos && bzr init /tmp/emptyrepos && bzr send -r 1..last:1 -o - /tmp/emptyrepos | gzip > mybackup.bzr.gz
That will create a bazaar native format merge-directive which you could apply to an empty repository to re-create all state.
Alternatively, it's likely safe to just tar up the current checkout. The on-disk format should be designed to safely deal with partial updates you may grab with tar.