-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_branches_and_head.txt
48 lines (47 loc) · 3.72 KB
/
git_branches_and_head.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
HEAD | It is the current snapshot of the project
HEAD | Is a "reference" to currently checked-out branch or commit
HEAD | It is locally significant
HEAD by default points to ".git/HEAD"
The contents of the ".git/HEAD" is "ref: refs/heads/master"
----------------------------------------------------------------------------------------------
Suppose we delete 3 files in the staging area.
Then if it has to be moved to staging area, you still have to do a "git add ."
----------------------------------------------------------------------------------------------
Change the reference to a specific branch with "git checkout <branch_name>"
Change the reference to a specific commit with "git checkout <sha1>"
----------------------------------------------------------------------------------------------
If during "git commit" , -m is ommited, then it will take to vim editor
Press "i" to enter insert mode to add a commit message
To exit, press ":wq"
----------------------------------------------------------------------------------------------
** Even after git commit -m "<Deleted all 3 files>" the Repository still has all the files.
If you go to .git/objects, all the objects would be visible the blobs
(file1.txt, file2.txt, file3.txt are not deleted from the Git repository) **
They are just deleted as part of commit and hence that tree would be empty
Even after deleting the files in the WORKING DIRECTORY and in STAGING AREA, the Git Repository will
have files (Object folders will have reference to the objects created)
----------------------------------------------------------------------------------------------
git checkout | It is used to move to a specific version of the project.
It moves the HEAD to another branch
Takes the specific snapshot from GIT repository and places it in STAGING and WORKING DIRECTORY
Under the hood, GIT moves the head pointer to a specific commit
----------------------------------------------------------------------------------------------
Detached HEAD | When the HEAD points to a commit instead of a specific branch
If we have 3 commits and if we checkout (move HEAD) to the 2nd commit, we will not be able to see any information related to 3rd commit
----------------------------------------------------------------------------------------------
By moving the HEAD, we moved to a specific version or specific snapshot of the project
----------------------------------------------------------------------------------------------
BRANCHES | It is a separate history of a project
----------------------------------------------------------------------------------------------
We checkout with BRANCHES rather than commits because, we dont have to remember the SHA1 Hash value.
If we add new commits in Detached HEAD (commits), if we move the HEAD, all the commits on that Detached HEAD are lost
----------------------------------------------------------------------------------------------
git branch | Gives a list of all the local branches and * is marked for the current branch
git branch <branch_name> | Creates a new branch with name <branch_name>
git checkout <branch_name> | Checks-out or moves to the new branch
git branch -m <old_branch> <new_branch> | Renames a branch from <old_branch> to <new_branch>
git branch -d <branch_name> | Deletes the branch with name <branch_name>
git checkout -b <branch_name> | Creates a new branch <branch_name> and also Checks out , i.e points to the new branch
----------------------------------------------------------------------------------------------
Git reuses blobs if the contents are same even if the file names are different
----------------------------------------------------------------------------------------------