笔记基本上整理自网站 Try Git，一套很不错的 Git 在线入门教程。
To initialize a Git repository here
- A folder used for storing multiple files.
- A directory where Git has been initialized to start version controlling your files.
See what the current state of the project is.
- Files are ready to be committed.
- Files with changes that have not been prepared to be committed.
- Files aren’t tracked by Git yet. This usually indicates a newly created file.
- File has been deleted and is waiting to be removed from Git.
Add files to the staging area.
- A place where we can group files together before we “commit” them to Git.
- You can also type
git add -A. where the dot stands for the current directory, so everything in and beneath it is added. The
-Aensures even file deletions are included.
You can use
git reset <filename> to remove a file or files from the staging area.
A “commit” is a snapshot of our repository. This way if we ever need to look back at the changes we’ve made (or if someone else does), we will see a nice timeline of all changes.
git commit -m “msg”
- To store our staged changes we run the commit command with a message describing what we’ve changed.
- Auto removes deleted files with the commit.
git commit -am "msg"
a journal that remembers all the changes we’ve committed so far
git log –summary
- see more information for each commit. You can see where new files were added for the first time or where files were deleted. It’s a good overview of what’s going on in the project.
git remote add <remote name> <repository URL>
Git doesn’t care what you name your remotes, but it’s typical to name your main one
It’s also a good idea for your main repository to be on a remote server like GitHub in case your machine is lost at sea during a transatlantic boat cruise or crushed by three monkey statues during an earthquake.
Tells Git where to put our commits when we’re ready.
git push -u <remote name> <branch name>
-u tells Git to remember the parameters, so that next time we can simply run
Sometimes when you go to pull you may have changes you don’t want to commit just yet. One option you have, other than commiting, is to stash the changes.
Use the command
git stash to stash your changes, and
git stash apply to re-apply your changes after your pull.
git push <remote name> <branch name>
Check for changes on remote repository and pull down any new changes.
A good overview of changes we have made and lets us add files or directories one at a time and commit them separately.
git diff HEAD
- Show what is different from our last commit.
HEADpoints to your most recent commit by default.
git diff –staged
- Look at changes within files that have already been staged.
git checkout –
Changed files back to how they were at the last commit, namely get rid of all the changes since the last commit.
--: promise the command line that there are no more options after the ‘–’, avoid switching to the branch of the same name.
List local branches of now repository.
- Create a new branch.
When developers are working on a feature or bug they’ll often create a copy (aka. branch) of their code they can make separate commits to. Then when they’re done they can merge this branch back into their main master branch.
- Switch to certain branch.
git checkout -b new_branch
- Checkout and create a branch at the same time.
Not only remove the actual files from disk, but will also stage the removal of the files for us.
git rm -r folder
- Recursively remove all folders and files from the given directory.
Merge your changes from the given branch into current branch.
- Merge Conflicts can occur when changes are made to a file at the same time. Reading more on how conflicts are presented.
git branch -d
- Delete a local branch.
-dwon’t let you delete something that hasn’t been merged.
- Force delete the branch that hasn’t been merged.
-f(–force) option or use
-d -ftogether into one command.
Delete Remote Branch
git branch -r -d <remote name>/<branch name>
git branch -r -d origin/branch-name