git Flashcards
What is a git repository?
A git workspace with its own history. It’s like a clade. What you do to one repo does not affect the others.
Command to get info on the repo we’re currently in.
git status
Command to initialize a new empty repo in the current directory.
git init. Use mkdir and cd into it, then use git init inside that directory.
What is a commit?
Basically a snapshot of code in a repo.
Difference between saving a file and committing a file.
You save a file(s) first, then group them together into a commit.
How does a commit work?
You group some or all altered files together and commit them. So if you alter 10 files, you can choose a specific group of 3, for example, to commit.
Difference between working directory & repository.
Working directory - the dir where the files you’ve created reside.
Repo - the .git folder that’s created in the dir with your files when you use the git init command.
What is the staging area?
This is what we add our changes to before making a commit.
Command to add files to the staging area.
git add
Command to create and add two files to the staging area.
touch file1.txt
touch file2.txt
git add file1 file2
Command to add all changes in the current dir to the staging area.
git add .
What is a git message?
A message you write when you commit files which explains what has been changed in those files.
Command to write commit message with a commit.
got commit -m “message”
What info does git status give you?
If there are any modified files that haven’t been added or committed.
Command that gives you a log of the commits for a given repo.
git log
What info does git log give you?
It gives you a log of the commits for a given repo, who made the commits and at what time they were made, and the message associated with each commit. Also a list of all branches & where HEAD is currently pointing.
What does it mean to keep commits atomic?
When you make a commit, try to focus on one thing. If you alter a particular GUI element and also alter some other thing like button functionality, make separate commits with messages for each of these changes, don’t commit both simultaneously.
What command lets you amend a commit?
git commit –amend
(only works on previous commit)
When should you use git commit –amend?
If you do a commit but forget to add one of the files you wanted to commit to the stage beforehand.
How does git commit –amend work?
It opens up the previous commit message and allows you to edit it, so you could basically re-do the previous commit command with the file you forgot.
Command to use if there are files you don’t want to make public or be tracked by git.
git ignore