Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Monday, March 7, 2016

Using git-stash without losing staged changes

When I learned about git-stash, my productivity with git from the command line went way up. But it wasn't until recently that I figured out how to properly handle the situation where I had already staged changes but needed to stash everything to do something without .

The problem comes from the fact that stash lumps all the changes to the tracked files together, without separating all the things you've added to the index. If you've done a patch add with git add -p, this can mean a lot of frustration at having to pick through all the changes again once you do git stash pop.

To avoid this frustration, do the following and you'll be able to keep your staged changes over the course of using stash.

1. First, do a stash of only the things you haven't yet staged:
git stash save --keep-index "Un-staged changes"
At this point, if you run git status, you should see all your changes that have been staged still there, but none of the changes NOT staged for commit (except of course for any untracked files).

2. Next, stash the staged changes as you normally would:
git stash save "Staged"

3. Now is when you want to do any work you need to while the other changes are stashed. NOTE: If you need to make changes that are based on a file in the "Un-staged changes" stash, you will of course need to pop that stash specifically with git stash pop stash@{1}. But, in order to get the staged changes back, you'll need to do another git stash save to do things in the correct order.

4. To get your changes back, you're going to pop them off the stash in the reverse order. If you haven't stashed any other changes, you can do a simple pop:
git stash pop
Otherwise, you should run:
git stash list
and find the correct name of the stash to pop, e.g. stash@{1}.

5. All the changes you just popped aren't staged at this point but should be, so go ahead and add all of them to the index with git add file1 file2 ...

6. Finally, run git stash pop one more time to recover the un-staged changes you saved in step 1 and you'll have everything back to the way it was at the beginning.

Friday, February 26, 2016

How to check out an old version of Chromium OS

You gotta love the combination of open source projects and git. Getting up and running with a project like Chromium OS is pretty straightforward with the guide available on the Chromium Wiki. But what if, for some reason, you're interested in a version other than the most recent? How do you dig through the combinations of repositories to get it? I recently had to figure this out for a project I'm working on, so I thought I'd pass it along.

First off, you should know that version numbers between Chrome, Chrome OS, Chromium, and Chromium OS do have a certain correlation, but isn't guaranteed to be the same across the repositories for all of them.

Once you've figured out which version of you want, go to https://chromium.googlesource.com/chromiumos/manifest-versions/+/master/paladin/buildspecs/, click on the version number in the list, then select a build number from the next page.

What you see next is a long XML file that tells repo (Google's wrapper around git) what versions of all the Chromium repositories correspond to that build number. Scroll all the way down to the bottom of the page and click on the "txt" link to download it. This will be a Base64-encoded version of the XML file you were just looking at.

Next, decode the text file with a command like this:
base64 -d [manifest_version].txt > [manifest_version].xml
This assumes you're working on a *nix system. A quick Google search will help Windows users. Be sure to replace [manifest_version] as appropriate.

Assuming you've checked out the Chromium OS repositories before using the repo command, run the sync command using the manifest you just downloaded with:
repo sync -m /path/to/[manifest_version].xml
If you haven't checked out the repositories before, follow the instructions on the guide listed above, then replace the repo sync command with the one above. Keep in mind that the sync process takes a VERY long time.

At this point, if you were to try and enter the SDK with the usual cros_sdk and do any commands, they would likely fail because it is too new. Get the appropriate version with:
cros_sdk --replace
This command will also take a long time to complete.

Now you can enter the SDK with cros_sdk. Now you should rebuild all the packages with:
build_packages --nowithdebug --board=${BOARD}
This command will also take a long time to complete.

Finally you can build an image with the usual command (adding any extra flags you need):
build_image --board=${BOARD}

That's it! Good luck working with Chromium OS!