Advertisement

Responsive Advertisement

Git Undo latest by ADAM

VVVIMP:

Git Internals:
Nice blog and youtube playlist of the same

For hands on do this handon

Git Internals series:
Git data model: here
Branching: here
Index or staging: here
  • When we create a file, nothing will happen
  • when you add file to stating area uisng git add . ,new bobs are created for the files which you added into staging area
  • Let say you created 3 files and contents of 2 files is same , then it will create 2 blobs in .git/objects
  • Index file is also updated, if we use git add .
  • When you commit, then 2 objects were created. one is tree object that points to all blobs and another is commit object that points to tree object
  • Lets say if you want to create another commit, for that first you create another 2 files with different content
  • when you use git add . 2 blobs are created ..So total we have 4 blobs 2 blobs in first commit and another 2 in his commit
  • When you use git commit now, 1 tree object and another commit object will be created
  • If you observe closely that tree which was created as part of second commit points to all the four blobs
  • So at any point of  time, a commit has snapshot of enire project not the diffs between earlier commits.
  • When we create a branch, a new ref will be created in .git/refs/heads/<branchname> that points to latest commit of  source branch
  • When we checkout to that branch, the value inside .git/HEADS will be changed to current git name i.e ref: regs/heads/<branchname>

3. Why Index?

Git index, or Git cache, has 3 important properties:

  1. The index contains all the information necessary to generate a single (uniquely determined) tree object.
  2. The index enables fast comparisons between the tree object it defines and the working tree.
  3. It can efficiently represent information about merge conflicts between different tree objects, allowing each pathname to be associated with sufficient information about the trees involved that you can create a three-way merge between them.

Git Undo latest by ADAM

video 

If we want to do undo, there are 3 stages depending on which you will do undo:

1.Working Directory

2.Staging area 

3.Local Repo


1.Working Direcory:

If you want to undo changes from working directory.It is always good option to backup changes before undo.

Whatif I tell you there is a method/process, which will do backup and undo at the same time and with an ease.That is git stash.

It is always recommended to use git stash, if you want to undo changes for the files in working directory,Even you can restore backup files using git stash

 Git stash:(refer here)

  • It is used for backup and restore.
  • All the files should be in working direcory or staged  in modified state(beacuse you will do backup only when you modified some thing)
  • After applying the changes, the files which restored changes will come to working directory
  • Before applying changes, git status should show 'noting to commit, working tree is clean', because if there are modified files in working direcory git will confuse where to apply changes ,wheather override is required or not

2.Staging Area:

We need to know repository reference concept before using this.

repository reference: It is internally used by git to track changes on top of latest commit,If we see git commit we see the commit ids and Head Ref points to latest commit that is the reason why we can see all the latest changes to files,If we move the headref to previous commit then we can see changes to files at that point of time.
When we add files to staging area, a temporary reference will be created and headref points to that reference.

There are three flavours of git reset:
1.Soft
2.mixed
3.hard

1.Soft:
git reset --soft

 

Post a Comment

0 Comments