git push - where's my commit hash - git log is not showing in the history MIRROR repository

2k views Asked by At

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 [email protected]: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).

[[email protected] ~/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)
[[email protected] ~/aks/always-latest-ws-repogroup/ansible] $ 


[[email protected] ~/aks/always-latest-ws-repogroup/ansible] $ git add mycompany-ansible.yml roles/mycompany.mycompany-ansible

[[email protected] ~/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
[[email protected] ~/aks/always-latest-ws-repogroup/ansible] $ 


[[email protected] ~/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
[[email protected] ~/aks/always-latest-ws-repogroup/ansible] $  


[[email protected] ~/aks/always-latest-ws-repogroup/ansible] $ git log -1 --pretty=format:%h 
a10cb09


[[email protected] ~/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  [email protected]:mycompany/ansible.git (fetch)
origin  [email protected]:mycompany/ansible.git (push)

and

$ git reflog 
a10cb09 HEAD@{0}: clone: from [email protected]: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?

1

There are 1 answers

13
VonC On BEST ANSWER

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.