fatal: ambiguous argument '–hard': unknown revision or path not in the working tree. Use '--' to separate paths from revisions - git-reset

I am trying to execute the below git commnand:
git reset –hard DI_BINARY_REPOSITORY_IMX6_LINUX_14.4C504.2
but I am getting the following error:
fatal: ambiguous argument '–hard': unknown revision or path not in the working tree. Use '--' to separate paths from revisions"
What am I doing wrong?

You are using the wrong character for options. "–" != "--"

Here is my situation. I got same error when trying to return to very old commit. I found out that my local repo did not contains this commit. Adding param depth=num_of_commits_to_fetch resolves issue. Example:
git pull --depth=1000
git reset --hard 9e766b9

two possibilities:
Are you passing the right parameter after hard? You need to specify which commit tag to reset to. HEAD and HEAD~1 (One commit before HEAD) are common.
Is that one dash or two you have with hard? It should be 2.

Feth remote repo details first by below command.
git fetch --all
Then hit below command
git reset --hard DI_BINARY_REPOSITORY_IMX6_LINUX_14.4C504.2

Related

Get gerrit commit with only short hash [duplicate]

When working with Gerrit (Code Review), I often need to get a copy of a given patch set for testing or validation purpose. The obvious and easiest way is to download the archive or the patch file through the Gerrit Web interface and manually apply it to my local source.
While the above steps are pretty straightforward and fulfill my needs, in the best world I would like to have the patch set appearing as a commit in my local Git.
I was looking around and didn't find the solution. I found some sparse info that once compiled together gives the following solution.
Say that you want to pull the patch set 2 of the Gerrit change 1222:
Find the remote refs we are interested in:
$ git ls-remote | grep 1220
From http://something.com:8081/MyProject
e2e0212a59240ac5cd7c11220c35542523f44b59 refs/changes/13/713/1
b8c4dceea5eaf1bad711b0ea6938c80ec932726a refs/changes/20/1220/1
6f20c182ec7f54a2aa9e8f6188a0eef1b0790df4 refs/changes/20/1220/2
ed94a98386d224ce3d86004ce99f61220905a077 refs/changes/22/1222/1
Pull the refs:
git pull origin refs/changes/20/1220/2
This will create a Git commit point that you could eventually rebase:
git rebase
This feature is standard in the Gerrit UI.
On the top right of the UI for a patch, click Download, and you will see something like:
When you are navigating the patches you go to the download section and copy the command line command for checking out the patch set, for example like this:
git fetch https://gerrit.googlesource.com/gerrit refs/changes/03/64403/2 && git checkout FETCH_HEAD
Then I normally create a branch with the review number and patchset as name
git checkout -b b64403-2
For here you can work normally and commit your changes or cherry-pick/rebase your changes on this change.
Once the review of r64403 is done your code can be merged or when there is another patchset submitted you will need to do the same thing again.
If you do not see the options to download the option to Checkout or Cherry Pick you need to edit the gerrit.config, something like this:
[download]
scheme = ssh
command = checkout
command = cherry_pick
More details can be found in the Gerrit Documentation
Update:
As barryku correctly points out, in the later version you need to download the downloads-commands plugin. This can be done during the initial setup or by using the following command:
java -jar gerrit-2.11.4.war init -d review_site --batch --install-plugin download-commands
Or you can use the -d option to git-review. For example, assuming you were working the with nova-docker repository and were interested in this change in gerrit:
https://review.openstack.org/#/c/148486/
You could download the latest patchset like this:
git review -d 148486
Or you can use the change id:
git review -d I35729a86e211391f67cc959d19416c9125c6f9eb
You can also request a specific revision of the patch by appending a comma and the patch number. E.g, to get the second revision of that patch:
git review -d 148486,2
I am not 100% sure what your question is. Sounds like you want to easy the workflow or typing. larsks mentioned already git review which is mostly used.
For your case, maybe it helps to download all ref's automatically so you can reference them directly. You can always all specified ref's like with
git fetch origin "+refs/changes/*:refs/remotes/origin/changes/*"
Then you can work locally with the commit id.
A simple git alias or scripting it for all refs can be easily done. An example of such a while loop can be found in the script on https://github.com/saper/gerrit-fetch-all With such a small shell snippet you can easily accomplish to skip one part of the ref id to easier reference them:
Server side: Client side:
refs/changes/13/713/1 refs/head/713/1
refs/changes/20/1220/1 refs/head/1220/1
refs/changes/20/1220/2 refs/head/1220/2
refs/changes/22/1222/1 refs/head/1222/1
As mentioned in the comments, you can just get the right git command from the gerrit GUI. If you really dislike GUIs, or you want to automate it (and for some reason can't use git-review), you can use the gerrit API:
curl -s 'https://<your gerrit server>/r/changes/<change id>?o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS' | tail -n+2 | jq -r '.revisions[.current_revision].fetch["anonymous http"].commands.Pull' | bash -
or
git pull origin `curl -s 'https://<your gerrit server>/r/changes/<change id>?o=CURRENT_REVISION' | tail -n+2 | jq -r '.revisions[.current_revision].ref'`

Github pulling does not work in - Rails 5

I'm trying to pull last commit that I made on github, and though I get no errors, I see no changes in the code. I messed up my schema file, but after I pull the code it does not change at all.
I searched here on stack and the solution that worked for others didn't work for me, and this is also my first time that I'm pulling code from github, so I could've probably done something wrong.
I used this code:
git fetch origin controller-generator
git git reset --hard FETCH_HEAD
This is what I get as the output
HEAD is now at 1fb8c97 Integrated friendly routes gem
'Integrated friendly routes gem' is my last commit that I want to pull, but nothing changes. I don't know if I need one more step or whatever it goes with it.
This is what I have in commit db file
And when I pull this, I get this
The last one should not be there.
This is output
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git reset --hard 1fb8c97d64f389904b3048fb2850fcfd8425cd36
HEAD is now at 1fb8c97 Integrated friendly routes gem
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git push -f origin HEAD
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Everything up-to-date
The problem is still the same as shown in the pictures. db files did not change
If I understood, you are asking to reset your local/master with origin/master.
$ git fetch
$ git reset --hard origin/master
You can back (hard reset) to a commit that was working for you.
$ git reflog # copy the commit-sha where you want to back/reset
$ git reset --hard <commit-sha> # reset to the commit
Now, if all things are ok. Then Force (-f) Push to remote.
$ git push -f origin HEAD # update remote branch

How to deal with file names which contain spaces in Ruby(In Git Bash)

I encounter a problem about running some Git commands which contain white spaces in file names with Ruby, like:
aaa = "xxxxxxx/xxxx/BOM\ Explosion.txt"
`git update-index --assume-unchanged -- #{aaa}`
or
aaa = "xxxxxxx/xxxx/BOM Explosion.txt".shellescape
`git update-index --assume-unchanged -- #{aaa}`
I have tried either way above to escape space and run it in Git Bash, but neither of them work, with the error message:
fatal: Unable to mark file 'xxxxxxx/xxxx/BOM
Updated git index
Anyone have some ideas?
You can largely ignore escaping concerns if you specify parameters individually:
system("git", "update-index", "--assume-unchanged", "--", aaa)
This passes the arguments through directly without the shell interpreting them. This is the most reliable way to pass them through correctly.

Cleaning Git Repository: Rails Project, added Gems to Repo by mistake

I was trying to solve an issue with some gem conflicts, and I added all of my gems to vendor/cache, I have since removed them, but now I have a 40M pack file where it used to be less than 1M.
I have tried to filter the branch
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch vendor/cache' --prune-empty -- --all
This goes through a list of rm commands, for example:
rm 'vendor/cache/sass-3.2.8.gem'
and then at the end
Rewrite 9c90286ba515f46919e82e73e2c01a5db1762668 (202/202)
Ref 'refs/heads/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
Finally I run
git gc --aggressive --expire=now
But I still have the same huge number of objects, and the pack file is still 40M. I even try forcing a push when this was complete with no change. Any idea how I can clean up my repository following this mistake?
I think you'll find the answer at the bottom of the question or in the accepted answer here:
Remove file from git repository (history)
The key is in that warning line you have:
WARNING: Ref 'refs/remotes/origin/master' is unchanged
The solution discusses how to get rid of that so that the other steps accomplish what you want and reduce the size back down.

pushing to heroku git error

I have created a brand new heroku app, beforehand i deleted the old .git file from my app's directory and created a new one with the usual steps:
git init, git add ., git commit -m "new git"
all of which worked fine. I then created a new app like so and got the following error:
$ heroku create
Creating glowing-summer-56.... done
Created http://glowing-summer-56.heroku.com/ | git#heroku.com:glowing-summer-56.
git
Git remote heroku added
$ git push heroku master
Counting objects: 1553, done.
Delta compression using up to 4 threads.
fatal: object 91f5d3ee9e2edcd42e961ed2eb254d5181cbc734 inconsistent object lengt
h (387 vs 8985)
error: pack-objects died with strange error
error: failed to push some refs to 'git#heroku.com:glowing-summer-56.git'
This is strange to me, as it is a brand new .git file. How can I get rid of this without cleaning up each damaged object? Is there a way to just delete the git file and start anew? I'm not using this git file for anything other than pushing to heroku.
Also I should note that I am using Cygwin on windows and my git version is 1.6.6.1
I've come across this error before and fixed it, I just honestly can't remember how.
Finally, using git fsck --full yields nothing :(
Thanks,
i seemingly fixed this with: git reset

Resources