Git checkout commit hash in AOSP - android

I never used repo and I've just recently discovered that AOSP is composed of different git repositories.
My question is: how can I checkout between commits?
For example, let's consider this commit
which involves just one .java file (InstallStart.java)
I go to the folder that contains InstallStart.java, in my case:
/mnt/aosp/Android/packages/apps/PackageInstaller/src/com/android/packageinstaller
git log shows that I'm in git repository... but the checkout fails
git checkout 419c6b327562afc9af3bed5e92741e5bf190ec30
fatal: reference is not a tree: 419c6b327562afc9af3bed5e92741e5bf190ec30

Related

How can I download the starter branch version of code [duplicate]

To cut the story short, to run a convolutional neural network model, I need an special version of nolearn, which has a url of the form https://github.com/dnouri/nolearn/tree/1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn . However, there are no Download as Zip buttons at the page, nor I can download it with
git clone https://github.com/dnouri/nolearn -branch 1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn
Simply,
git clone https://github.com/dnouri/nolearn/tree/1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn
does not work, too.
Even, I have no idea what should I search for in Google!
Note: This is the last version which provided support for the class Objective, i.e. the command from lasagne.objectives import Objective is no more supported!
This can help you:
How to clone a single branch in git?
Where specifies:
git clone <url> --branch <branch> --single-branch [<folder>]
Docu :
Git Clone
--[no-]single-branch
Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary
branch remote’s HEAD points at. When creating a shallow clone with the
--depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches. Further
fetches into the resulting repository will only update the
remote-tracking branch for the branch this option was used for the
initial cloning. If the HEAD at the remote did not point at any branch
when --single-branch clone was made, no remote-tracking branch is
created.
Other than in Subversion (SVN), git has separate namespaces for directories (file system folders), branches and tags. Thus https://github.com/dnouri/nolearn/tree/1659e4811e498dc1f442d8e6486d0831f85255b4/nolearn is not, per se, a branch. 1659e4811e498dc1f442d8e6486d0831f85255b4 is a commit ID, used here to refer to the revision created by the commit. dnouri/nolearn is the repository name on GitHub (repository nolearn on account dnouri) and the final nolearn in the URL is a directory within the content of revision 1659e4811e498dc1f442d8e6486d0831f85255b4.
The 'normal' way to get this code with git would be:
replicate the repository to your local machine
git clone https://github.com/dnouri/nolearn.git
(You can find this URL on the repository's page https://github.com/dnouri/nolearn, in the 'clone URL' field.)
enter the local repository
cd nolearn
check out the wanted revision
git checkout 1659e4811e498dc1f442d8e6486d0831f85255b4
change into the respective directory inside the repository
cd nolearn
This is the link to the .zip : https://github.com/dnouri/nolearn/archive/1659e4811e498dc1f442d8e6486d0831f85255b4.zip

How can I solve "fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree"?

I have only one commit on master and haven't merged it into the remote. I want to remove my commit, keep my changed files, change my branch, and commit them.
Now I have used git reset --soft HEAD~1, but I am faced with this error:
fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
HEAD~1 is a way to point at "the parent of current commit"
In your situation: the (only) commit on master does not have a parent ...
If your intention is to have this commit on another branch, simply create that other branch:
git checkout -b my/branch
# The above is a shortcut to:
git branch my/branch # Create a new branch `my/branch` on the current commit
git checkout my/branch # Switch to this branch
With one single commit in its history, "removing the commit from master" is the same as "deleting master".
There is no harm in doing it (you can re-create it later): git branch -d master, but you can also live with a local master branch hanging around.
An alternative is to amend the first commit:
# Make your change in the file(s)
git add file_changes
git commit --amend --no-edit
Resource: How can I add a file to the last commit in Git?
If this is from flutter, then the problem is simply from your installation process.
check your .git > refs , if the heads & remote directories are empty, then you simply have incomplete files.
Delete your current flutter folder and download again.
Ensure that 100% of the files are moved/copied during extraction

Android Studio git: failed to traverse parents error

I've been running Android Studio on Windows, with git doing the versioning, and git pushing using git bash for Windows. I've been doing the same thing for all that time, without issue.
Then today, in the event log in Android Studio after opening I see:
17:29 VcsException
error: Could not read 5188c7b8677be145b04f079e6f9cab08e5c19240
fatal: Failed to traverse parents of commit 50da9e67a67598125b860984db9e493bd5d1f2ee
during executing git -c core.quotepath=false log HEAD --branches --remotes --max-count=2000 --pretty=format:%x01%H%x02%ct%x02%an%x02%at%x02%ae%x02%cn%x02%ce%x02%P%x02%s%x02%b%x02%B%x02%d%x03 --encoding=UTF-8 --decorate=full --
And when I try a git operation in the git bash console (Windows) I get:
$ git commit -m 'new stuff'
fatal: unable to read tree 4dfc5598677be145b04f079e6f9cab0833555566
The following is an extract from running git fsck... there is a long list which annoyingly in git bash is not scrollable or selectable:
$ git fsck
dangling blob 7be145b04f079e6f9cab0835664dfc5598673555
missing blob e6f9cab0835664dfc559e145b04f07986735557b
missing tree b04f07986735557be6f9cab0835664dfc559e145
... (lots of dangling blob, a few missing blob, one missing tree) ...
What can I do to fix this?
So, since I've been pushing regularly to the remote repo so I know that is pretty up to date, I followed the low-tech suggestion set out here, combined with the first comment to that suggestion.
So:
create a temporary folder in whatever location you want
clone the repo into that folder with git clone
git#bitbucket.org:myaccount/myproject.git
move the .git folder in the existing project folder out into another temporary folder somewhere
move the .git folder from the repo cloned in step 2 into the project folder, to replace the old one moved out in step 3
and that was it... a git add / commit / push we seem to be
back on track

Getting "detached HEAD" error despite deleting git submodule

Git seems to be tracking the java folder, but I can't commit changes to the specific file MainActivity.java. I get a "Changes not staged for commit"
The diff shows the changes, but I can't commit it.
Also, I can't go down into the folder in Github.
That folder is not clickable.
Edit: When I do git status in the command line, I get
user:JustJava juil$ git status
HEAD detached at 93ea9a1
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: app/src/main/java/com/example/android/justjava (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
Edit 2: I have checked out the latest commit as some have suggested but still get the detached head error.
Edit 3: I tried adding the file itself w/ git add but got an error that the directory is a submodule.
JustJava juil$ git add app/src/main/java/com/example/android/justjava/MainActivity.java
fatal: Pathspec 'app/src/main/java/com/example/android/justjava/MainActivity.java' is in submodule 'app/src/main/java/com/example/android/justjava'
I tried running git submodule status and got the error
fatal: no submodule mapping found in .gitmodules for path 'app/src/main/java/com/example/android/justjava'
I tried deleting .git in the submodule, but the same error keeps popping up.
To correct this using just the Android Studio interface, try the following:
Make a backup copy of your changed files, just in case this method doesn't merge your changes correctly.
In the version control pane, select the Log tab. It will show you a list of commits.
The top commit should be the newest one. Right click it and select Checkout Revision in the context menu.
If a dialog appears, select Smart Checkout. This will merge your changes with the selected commit.
Your HEAD should now be attached, so you can commit normally now.
When your HEAD is detached, it means you did the commandline equivalent of:
git checkout <UUID of previous commit>
The grey folder that was created is called a submodule, it happens when you initialize a git repository inside another git repository. I would suggest removing the .git folder inside JustJava/app/src/main/java/com/example/android/justjava.
Using git through terminal, follow these steps:
Backup all the code in a different folder
**Remove JustJava/app/src/main/java/com/example/android/justjava/.git"
Checkout out master or the current branch you're on (default: master)
In order to checkout master, go to the folder where you git project is through the terminal (linux or mac) or git bash (if you're on windows), then do:
git checkout master
Comparing backed up code with the current code and make the changes you want (if any)
Commit new code
Since justjava folder turned out to be a submodule, in the super directory, I called git rm -rf --cached justjava as suggested by #fusiongate and answered in this question.
This works in that it allows the file to be added and committed, but the commit history on this file is lost.

Cloning a subdirectory of a repository off GitHub using Android Studio

I was wondering whether it is possible to clone a subdirectory of a repository off GitHub using Android Studio? Usually when you clone a repository, you go "Check out project from Version Control" --> GitHub --> then you get something like this
However, for example, I would like to clone this subrepository as I would like to build the project and put it in my emulator. This address is https://github.com/hmkcode/Android/tree/master/android-material-design-appcompat.
I have tried to guess https://github.com/hmkcode/Android.git might have becomehttps://github.com/hmkcode/Android/android-material-design-appcompat.git, but this did not work.
Is it possible to clone this subrepository as I dont want the rest of the repository. I dont want to have to clone the whole thing and try to piece together the sub project.
This is not a "subrepo": it is just a subdirectory, and git reasons at the repo level.
You could use sparse checkout though, but it is not supported directly by Android studio. You would have to prepare your local repo:
mkdir hacker-scripts
cd hacker-scripts
git init .
git config core.sparseCheckout true
echo 'android-material-design-appcompat/' > .git/info/sparse-checkout
git remote add -f origin https://...
git pull origin master

Categories

Resources