Gitx show all commits8/30/2023 Maybe your customer or your team leader has told you to get rid of a feature branch, maybe it was your own idea to clean up. The next example resembles our first scenario: we’re going to delete something-this time, it’s an entire branch that has to go. Let’s look at another example and use the Reflog to recover an entire branch. Let’s take a look at our graphical Git client again:Īs you can see, the new branch, happy-ending, has been created and it includes the commits we deleted earlier-awesome, nothing is lost! But in this case, I’m going to create a new branch based on the old state: $ git branch happy-ending e5b19e4 You could use git reset again, which is totally valid. Copy the hash ID (which is e5b19e4 in this specific example) to the clipboard, like before. So, let’s use it to undo that last action and restore the state before the reset command. The journal seems to work-that’s good news. And, if you look closely, you will notice the fatal git reset action from a few minutes ago right at the top. That means: the most recent-the newest-commits are at the top. You’ll notice that all entries are ordered chronologically. Type git reflog to view the journal in your terminal: Now, let’s assume this was a mistake and take a look at the Reflog to recover the lost data. All we need to do is copy the hash ID to the clipboard and then use git reset on the command line and enter that hash: $ git reset -hard 2b504bee We want to get rid of two commits and make the “Change headlines for about and imprint” commit (ID: 2b504bee) our last revision on the master branch. The next image shows our original commit history in Tower, a graphical Git client: So, let’s mess things up and make this mistake in real life. In other words: keep calm and use git reflog! You’ve just lost valuable changes and start to panic!ĭo you really have to start from scratch again? You don’t. You courageously perform a git reset, the two commits disappear from the commit history… and a while later, you notice that this was a mistake. Imagine the following scenario: After looking at your commit history, you decide to get rid of the last two commits. To adjust the Reflog’s expiration date for the user or the system, add the -system or -global parameter to the commands shown above.Įnough theoretical background-let me show you how to work with git reflog to correct mistakes. git/config), the global per-user configuration ( $HOME/.gitconfig), and the system-wide settings ( /etc/gitconfig). Tip: Remember that Git makes a distinction between the repository’s configuration file (. git/config) now includes the variable reflogExpire with the value Īlternatively, you can decide that your Reflog should never expire: $ git config gc.reflogExpire never To change the number of days to 180, simply type the following command: $ git config gc.reflogExpire The repository’s configuration file (. Git’s diary usually gets cleaned up after 90 days (that’s the default setting), but you can easily adjust the expiration date of the Reflog. git/logs/refs/heads/ and it tracks the local commits for every branch. This local recording technically isn’t part of the repository and it’s stored separately from the commits. That’s why you can think of it as some kind of “undo history” like you might see in word processors, text editors, etc. Instead, it shows an ordered list of all commits which HEAD has pointed to in the past. It doesn’t go through the list of ancestors. Git reflog, on the other hand, is a private and workspace-related recording. It’s part of the repository which means it gets replicated after you push, fetch, or pull. The log goes all the way back in the commit history by recursively printing every commit’s parent. its parent, the next parent in line, etc. It shows the current HEAD and its ancestors, i.e. In previous articles, I’ve recommended you use the git log command to inspect previous events and look at your commit history, and that’s exactly what it does. Git log or git reflog: what’s the difference? Part 8: Using the Reflog to Restore Lost Commits ( You are here!).Part 3: Better Collaboration With Pull Requests.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |