chap 3 Flashcards
Add a file
git add filename
Adding the Changes to an Existing File
git add filename
Adding Partial Changes
git add -p
git add –patch (-p)
This is an important feature, since it helps you to make well- factored commits. When you’re done with some editing and ready to commit, you may realize that you’ve made changes that ought to be represented by more than one commit; perhaps you’ve fixed two bugs in the same file, or tidied up some unrelated comments while you were at it. git add -p allows you to con‐ veniently split the work up into separate commits.
Adding Partial Changes to particular file
git add -p filename
Include all files in the current index; this includes changed and deleted files, but not new ones.
git add -u
Include all filenames in the index and in the working tree; this stages new files as well.
git add -A
remove a file
git rm filename
This does two things:
1. Deletes the file’s entry from the index, scheduling it for re‐moval in the next commit
2. Deletes the working file as well, as with rm filename
Renaming a file or moving a directory in Git
git mv foo bar
Remove files from statging
git reset // for all files
git reset filename // particular file
Show the changes that are in staging and ready for commiting
git diff –cached
Commit and add a message
git commit -m “an interesting commit message”
commit workflow
- Use git add (with various options) to stage a subset of your changes.
- Run git stash –keep-index. This saves and undoes your outstanding, unstaged changes while preserving your stag‐ ed changes in the index, and resets your working tree to match the index.
- Examine this working tree state to make sure your selection of changes makes sense; build and test your software, for example.
- Run git commit.
- Now, use git stash pop to restore your remaining unstag‐ ed changes, and go back to step 1. Continue this process until you’ve committed all your changes, as confirmed by git status reporting “nothing to commit, working direc‐ tory clean.”