Recover Specific Data by Using Git Commands
Trace and Recover Data
When working with Azure Repos, developers sometimes need to find lost commits or see what happened in the past. Two commands help with this: git reflog and git log. The git reflog command logs every change to branch pointers, even for commits that no branch points to anymore, which makes it useful for finding work that would otherwise be lost. The git log command shows the history of commits in a linear fashion, which helps developers see the sequence of changes over time. Together, these commands let you locate missing history so you can decide what to recover.
Restore Files and Branches
Once you've found the commit you need, several commands can restore files or branches to that point. git checkout switches your current branch or restores a specific file to how it looked at a chosen commit, which is helpful when you want to examine old code without changing your branch. git revert creates a new commit that undoes the changes from a specified commit while keeping the original history intact, which makes it safe for shared branches where you don't want to rewrite history. git reset moves the branch pointer backward and can optionally update the staging area or working directory, which is useful when you want to unstage changes or completely remove commits from your current branch. The choice between these depends on whether you need to preserve history or clean up your branch.
Retrieve Stashed Changes
Sometimes developers need to temporarily save work in progress without committing it. git stash takes your modified tracked files and stores them in a hidden area, which lets you switch branches or pull changes without committing incomplete work. Later, git stash apply or git stash pop retrieves those changes so you can continue working. git cherry-pick takes the changes from a specific commit and applies them onto your current branch, which is useful when you want to bring in a bug fix or feature from another branch without merging the entire branch. These commands give developers flexibility to manage work across branches without losing progress.