Create a branch from master git3/5/2023 ![]() You’ve deleted the local branches, but we pushed copies of those branches to github when you ran git push -all. $ git branch -d branch-master Step: Delete the remote branches $ git branch -d planets-before-merge-conflict Now, if you want, clean up your repository by deleting the redundant branches. It will be like you never checked out the old commit. This will revert your working copy to the contents of the master branch. When you’re done exploring this feature, go back to the master branch by running Try running git log and see what it shows as the history. Note that the git history for this ‘detached HEAD’ state is the git history that you would have seen when this commit was written to git. In this example, planets.md will say there are eight planets. With your working copy in this ‘detached HEAD’ state, you will see the files exactly as they were when the commit was written to git. This is great for poking around in your git history, but you will eventually want to either check out one of your branches or you will want to create a new branch with this commit as its head. This means your working copy is showing a state of the repository that is not the HEAD of any of your branches. This will warn you that “You are in ‘detached HEAD’ state.”. You can make the working copy of your git repository match the state in that commit by running The first 8 characters will be enough to uniquely identify the hash, so we’ll use ca41886d in the example. For this example, we will pretend the hash for that commit is ca41886daca7f55aa7d88a5ae7b226dd3e670739. For example, the hash for the commit with the log message “pluto is not a planet.”. Run git log and pick the commit hash for any of the old commits. To do this, you need the commit hash from running git log. You can also restore a specific state from your history by checking out that commit. You will see that the git history in branch-master contains all of the commits from the other branches, with exactly the same commit messages and hashes. To confirm this, compare the commit hashes that you see when you run git log master against the commit hashes in each of the other branches. Now that you’ve merged your work into the main master branch, you can delete all of the other branches without losing any history because the master branch actually contains all of the work from all of the branches, including the entire history of changes. Step: Confirm that the master branch has your whole history With the branch-master branch checked out, merge the work from branch-a to branch-master by running $ git checkout -b branch-master Step: Start merging the work into the fake “master” branch Now create a new “branch-master” branch where we will combine everyone’s work $ git checkout planets-before-merge-conflict To create the fake “master” branch, checkout the planets-before-merge-conflict branch which contains the original version of planets.md by running This will let us compare all of the stages of the process before we finish. In normal use, you would merge these changes into the master branch, but for the purposes of this exercise we will create a fake “master” branch. On branch-a there is a commit with the message “sets the correct number of planets” while on branch-b there is a commit with the message “pluto is not a planet.” the commit messages are different AND the commit hashes are different. When you compare these two commits, you should see that both of them have the original commit with the message “planets.md before merge conflict” and that commit hash is the same in both branches but each branch has a different commit after this one. Output the commit history for each branch by running ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |