Exercises - Basic Concepts¶
- Create a repository, add (stage) and commit a file
mkdir repository
cd repository
git init
nano file.txt
git add file.txt
git commit -m "This is quite interesting"
where
Remember that the two-letter name of the subdirectory under objects-dir is included in the hash
- Make some changes.
Change one or more files. Add and commit. Make some changes. Add and commit.
Look at what happens in the .git tree
- Go to earlier commits and make a new branch
Try go back to an earlier commit with “git checkout
Make come changes to a file there, or try adding a new file (and add+commit)
Create a new branch from that commit: “git checkout -b second_branch”
Find the hash of the commit the HEAD points to now
- Go back on primary branch and merge the branches
Go back to the primary branch (main or master) with “git checkout main” or “git checkout master”
Merge the new branch you created to master with “git merge –no-ff second_branch” (or whatever you called the new branch)
Fix any conflict by going into the conflicting file(s) and removing the stuff you don’t want and also the git markers set there
Add the fixed file and do “git merge –continue”
Now look at what the HEAD is pointing to
- Check out the commit tree
You can also just try jump around in the commit tree with “git checkout
You get the list of hash’s and commit messages with “git log”