1

I cloned from a GIT repository (latest). At this point, the latest commit in the repository was: a10cb09

I cloned from using the following command (where I set variable r = 1st parameter passed (for repo name aka ansible) in my tiny wrapper script:

  git clone git@github.com:mycompany/${r}.git

and made few changes and did the following simple steps: (i.e. make changes, add file/folder, commit and push) and I got a new commit hash a08c263 (short).

[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    roles/mycompany.mycompany-ansible/
    mycompany-ansible.yml

nothing added to commit but untracked files present (use "git add" to track)
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ 


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git add mycompany-ansible.yml roles/mycompany.mycompany-ansible

[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git commit -m "mycompany.mycompany-ansible playbook and role" mycompany-ansible.yml roles/mycompany.mycompany-ansible 
[master a08c263] mycompany.mycompany-ansible playbook and role
 14 files changed, 1771 insertions(+)
 create mode 100644 roles/mycompany.mycompany-ansible/README.md
 create mode 100644 roles/mycompany.mycompany-ansible/defaults/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/handlers/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/meta/.galaxy_install_info
 create mode 100644 roles/mycompany.mycompany-ansible/meta/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/apt_install.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/main.yml
 create mode 100644 roles/mycompany.mycompany-ansible/tasks/yum_install.yml
 create mode 100644 roles/mycompany.mycompany-ansible/templates/10-statsd.conf.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/10-mycompany.conf.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/proxy_auth_credentials.set.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/telegraf.conf.wfcopy.j2
 create mode 100644 roles/mycompany.mycompany-ansible/templates/mycompany-proxy.conf.j2
 create mode 100644 mycompany-ansible.yml
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ 


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git push
Counting objects: 21, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (21/21), 18.65 KiB | 0 bytes/s, done.
Total 21 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:repogroup/ansible.git
   a10cb09..a08c263  master -> master
[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $  


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git log -1 --pretty=format:%h 
a10cb09


[arun@ip-10.20.30.33 ~/aks/always-latest-ws-repogroup/ansible] $ git rev-parse a08c263
a08c263
fatal: ambiguous argument 'a08c263': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

When I'm going to Github repo to see my latest changes, it's not there. git log is also not showing my commit (instead, it's showing me the commit hash which was at the top before my commit). What did I miss?

It seems like I can't even see the long hash using git rev-parse a08c263 (small hash).

$ git remote -v
origin  git@github.com:mycompany/ansible.git (fetch)
origin  git@github.com:mycompany/ansible.git (push)

and

$ git reflog 
a10cb09 HEAD@{0}: clone: from git@github.com:mycompany/ansible.git

PS: If I do the same steps for other repositories sitting under mycompany repo group and all those repos get my commit/push changes successfully in github if I follow the similar steps.

UPDATE: one of my browser page was still having this open. After I did commit+push, I was able to see my committed change(new hash a08c263 as the latest commit at the top repo level). When I clicked on it, it opened this attached browser page where I can see the FULL hash and also the folder/files. If I visit the opened browser URL for my commit, it's still there (so Git did save something) but clicking back on the repository's root level i.e. ansible, the latest commit is not my commit+push (new hash) but it's listing a10cb09 as the latest one (which per the snapshot is the parent hash for my newly generated hash). See here:

enter image description here

That now brings the main questions:

  1. If I didn't had this browser page still opened, then how would I have got the long hash and my folder/files (contents)?

  2. If I cloned from a github.com/mycompany/ansible (repo) which was a MIRROR of the ansible repository, actually hosted in Phabricator (where the actual original repository clone URL would be different than what I used in my tiny script above), then what command / option should I have used to push my new change to the original Phabricator ansible repository?

  3. If commit+push was complete at my end, why git log and other similar git commands are not showing any information against my new hash?

AKS
  • 14,113
  • 34
  • 144
  • 227
  • 2
    Any chance you pushed to origin instead of your own repository? Since you didn't define what to push to, it would default to origin master. What is defined as origin? `git remote -v` – Christia Dec 22 '16 at 03:28
  • 1
    @Christia But then why would the commit not even be showing up locally in the log? – Tim Biegeleisen Dec 22 '16 at 03:31
  • 1
    Post the top few entries of `git reflog` please – Christia Dec 22 '16 at 03:33
  • @Christia I added those details in my post. I mean, I do the steps for other repositories and they all show my commit each time. `ansible` repo sits as a sibling repo to those other repos as well but the same steps turned into the above issue. For testing, I tried to redo another test change/add/commit/push to 2 repos, one got my change and `ansible` again didn't. If the origin was incorrect, then it shouldn't have shown me the last commit hash (in the `git push` output as `a10cb09..a08c263` right)? Added `git reflog` output as well. I agree with Tim B. – AKS Dec 22 '16 at 03:47
  • OK, so this is what I found. `mycompany` repo group in github.com has many repositories (ansible is one of them). But, all those other repos are HOSTED on github.com itself, but this `ansible` repo that I cloned, is NOT HOSTED on github.com. `ansible` repo in my case is hosted in Phabricator and MIRRORED to Github.com (from where I cloned) it. Now, reading more `git` help, it seems like, If I have would have done `git push --mirror` then it would have worked (??), now, how can I get the same folders/files back using that `a08c263` hash and try `git push --mirror / -all` again w/o any rework. – AKS Dec 22 '16 at 04:12
  • OR I have to clone it from the correct repo URL (where it's actually hosted) and not from the MIRROR clone URL. The biggest worry is how can I get my folder/files from that `a08c263` commit back to my workspace. `git log` or `git rev-parse` is not showing anything / throwing an error, as that hash doesn't exist as per Git. It's very possible that for some crazy reason Phabricator wiped my commit as soon as it was committed / pushed) from where I cloned (mirrored github.com URL for `ansible`). – AKS Dec 22 '16 at 04:13
  • Does git see a08c263 between commit and push? – Antony Hatchkins Dec 22 '16 at 04:30
  • @AntonyHatchkins As per the git commit + push commands, those completed successfully giving a new hash (going away from last hash..new hash). I didn't mention earlier but I'm sure that my commit+push (as soon as it was done), was visible in github.com/mycomany/ansible repo (as the latest commit). I even clicked to see the diff thingy. I'm kind of lost here: why Phabricator removed it (if it did that for some reason), where did the hash commit data go locally, why this git shit is not showing me my commit details using that new hash (even though it was cloned from a mirror, who cares right?) – AKS Dec 22 '16 at 04:39
  • when I said, I did see my changes on Github.com/mycompany/ansible repo as the latest commit for hash `a08c263`, I'm right. Luckily the page that I browsed by clicking on latest commit against new hash, was still open in my browser & I'm glad can see the full hash + files committed in the commit/push too. I'll upload the picture as a proof. Visiting that link still works, shows me the files/folders that I committed, but if I click on the root repository in Github, it doesn't show my commit as latest, even though the snapshot shows parent hash and new hash. Parent hash is latest at repo level. – AKS Dec 22 '16 at 04:56
  • Did you try searching for a full hash? Maybe there's a collision of small hashes? – Antony Hatchkins Dec 22 '16 at 10:16
  • Are you sure you have no push triggers setup locally? Maybe some kind of git plugins? – Antony Hatchkins Dec 22 '16 at 10:17

1 Answers1

1

Visiting that link still works, shows me the files/folders that I committed, but if I click on the root repository in Github, it doesn't show my commit as latest

That means either that:

  • the default branch of the remote repo is not master
  • or some hook (post-receive?) set or reset HEAD to a different SHA1

this ansible repo that I cloned, is NOT HOSTED on github.com. ansible repo in my case is hosted in Phabricator and MIRRORED to Github.com (from where I cloned) it

That could explain the reset.

The biggest worry is how can I get my folder/files from that a08c263 commit back to my workspace. git log or git rev-parse is not showing anything / throwing an error, as that hash doesn't exist as per Git.

Sure: clone from github in another local folder, add your previous clone folder as a remote repo, fetch and cherry-pick your commit:

git clone https://github.com/... newfolder
cd newfolder
git remote add old ../path/to/first/clone
git fetch old
git cherry-pick a08c263
git push

But you need to make sure you have the right to push back to the GitHub repo.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • I agree with your conclusion. Any idea, if that Github link (which still shows my full new hash and folder and file contents) still works, then why at command line (Terminal window), where I did the git commit+push is not showing any info about that new hash, while Git is showing that for the commit URL. – AKS Dec 22 '16 at 05:34
  • @ArunSangal in your first local repo where you did commit `[master a08c263]`, what a `git status` shows you? – VonC Dec 22 '16 at 05:36
  • `On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working tree clean ` may be because, I already pushed the change so there's nothing new to the pushed OR I have just wiped out the whole repo (i.e. did fresh git clone to the same folder structure) – AKS Dec 22 '16 at 05:37
  • @ArunSangal so I suppose git log -1 is not showing you your latest commit? (which seems logical considering it is "p-to-date with 'origin/master'"). Can you check the same `git status` after a `git fetch`? Do you see your commit with a `git log --all --branches --oneline --decorate --graph`? – VonC Dec 22 '16 at 05:39
  • Yea the above colorful git log command didn't list my new hash. Showing the latest hash (which was parent hash to my commit new hash). `git log -1` also didn't list my commit when I checked it before I did cloned it fresh. So, is there any way I can get the contents as that Commit link URL per my snapshot is still showing folder/file contents? That link is still showing the top / latest hash from `git log` output as the parent hash for my new hash(committed version) – AKS Dec 22 '16 at 05:41
  • @ArunSangal What happen if you try and checkout (in your local clone) directly that lost commit? `git checkout a08c263` – VonC Dec 22 '16 at 05:42
  • for `git checkout ...` If I give use the short hash form, then I'm getting: `error: pathspec 'a08c263' did not match any file(s) known to git.` and if I'm giving the long/full hash, then I'm getting: `fatal: reference is not a tree: a08c263788aa77960e48861b78254e01a087df9` – AKS Dec 22 '16 at 05:45
  • @ArunSangal strange... I don't see why that commit would have been wiped out of your local repo. If you try and make a new commit with dummy changes, would that commit disappear as well? – VonC Dec 22 '16 at 05:47
  • That's a good question :). I'll try that for sure. I think I may have wiped my last workspace (after attempting a lot on why my new hash is not showing up). So, instead of doing `git push`, should I have done `git push --all` or `git push --mirror` to push my changes all the way upto the hosted repo (which I think is in Phabricator) or I must clone from the actual hosted clone URL loation? I mean, if commit + push was done successfully and didn't error out, then where did it go ??? :) it should have been in the log output even after I re clone into a brand new folder as git should maintain it – AKS Dec 22 '16 at 05:50
  • @ArunSangal cloning from GitHub seems safer (provided you have the right to push back to that repo) – VonC Dec 22 '16 at 05:51
  • @ArunSangal on the remote side, your push has been lost by the mirroring nature of the Phabricator repo. On the local side... I don't know why your local commit is nowhere to be found (not in the reflog, not in the logs) – VonC Dec 22 '16 at 05:53
  • I think I do have access right otherwise, `git push` would have cried long back, right – AKS Dec 22 '16 at 05:53
  • @ArunSangal yes, you will see that right away at the first `git push` to the GitHub (not Phabricator) repo. – VonC Dec 22 '16 at 05:54