Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I created a new branch.

I thought creating a new branch would switch to it. I now know I should use this code instead git checkout -b <branch_name>

I worked on my file and got it working.

I did a commit and saw this message [detached HEAD decdc89] number of loops works

I still assumed I was on the branch I had created, and it would be a good idea to commit as my code worked.

Then I thought I would merge it

So I git checkout master

it said

Warning: you are leaving 1 commit behind, not connected to any of your branches:

I did git merge making-the-number-of-items-work

But it the work wasn't on that branch, obviously, it wouldn't have made many changes. In fact, possibly it merged old changes, I'm not really sure.

How can I find that original bit of code which appears to have been in detached head mode, or have I lost it? As I made a commit I'm sure there is a way back, but I don't know the commit number.

I tried git log --all but I can't see the commit message anywhere

Sorry for such a badly posed question I really don't know the terms for Git all that well yet.

1 Answer

0 votes
by (12.4k points)

 You can use the below command:

$ git log -- <filename>

And if you want to list all the files that are being tracked under a particular branch(let's say master) use the below command:

git ls-tree -r master --name-only

For more information on Git, you can join git training.

To know more about git commands, checkout:

Browse Categories

...