Must every git commit be an ancestor of a branch?

Given this git tree:

A <--- B <--- C (HEAD, master)

is it possible to put the tree into this state:

A <--- B (HEAD, master) <--- C

(There are no branches or tags other than master.) In other words, can a commit (C) exist without either being a commit pointed to by a branch (or tag) or the ancestor of a commit pointed to by a branch (or tag)?

(This question is purely theoretical to help me understand better how git branches works.)



git checkout -b tmp
touch whatever.txt
git add -A
git commit -m "committed!"
git checkout master
git branch -D tmp

The commit whose predecessor is the current HEAD of master is now still available, but no name is pointing to it. You can still get to it e.g. with the reflog commands.

Another possibility, given that C already exists:

git checkout -b tmp
git checkout master
git reset --hard HEAD-1
git branch -D tmp

ps, cannot find the tilde key on this kb...

Commit C can exist temporarily (as a dangling commit); once a GC occurs it will be reclaimed.


git fsck --unreachable

to see dangling commits and blobs. Note that because git has a notion of reflog what you've described won't create a dangling commit right away, C will stay in the reflog for a while. git maintains the reflog just in case you've made a mistake and need to recover something.

Need Your Help

How to get from input data while input ng-model is ngRepeat variable?

javascript angularjs angularjs-ng-repeat

I am trying to create a edit form which is already filled with exciting data as default as follows:

slideToggle is Sliding Multiple Div's Down

jquery class html slidetoggle

I'm using jQuery's slideToggle on an unordered list in order to make it expand menu items. The problem is that this effect makes all of my div's slide down along with it. How can I make the rest of...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.