$ git config --global user.name "Your Name" $ git config --global user.email youremail@example.com $ git config --global alias.co checkout git init git add . git status git commit -m "Initial commit" git log $ ls app/controllers/ application_controller.rb $ rm -rf app/controllers/ $ ls app/controllers/ ls: app/controllers/: No such file or directory $ git status # On branch master # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: app/controllers/application_controller.rb # no changes added to commit (use "git add" and/or "git commit -a") $ git checkout -f $ git status # On branch master nothing to commit (working directory clean) $ ls app/controllers/ application_controller.rb The missing directory and file are back. That’s a relief! $ git remote add origin git@github.com:<username>/first_app.git $ git push origin master ////branch $ git checkout -b modify-README Switched to a new branch 'modify-README' $ git branch master * modify-README ////edit ////commit $ git status # On branch modify-README # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: README -> README.markdown # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.markdown # $ git commit -a -m "Improved the README file" 2 files changed, 5 insertions(+), 243 deletions(-) delete mode 100644 README create mode 100644 README.markdown Be careful about using the -a flag improperly; if you have added any new files to the project since the last commit, you still have tell Git about them using git add first. ////merge $ git checkout master Switched to branch 'master' $ git merge modify-README $ git branch -d modify-README Deleted branch modify-README (was 2c92bef). # For illustration only; don't do this unless you mess up a branch $ git checkout -b topic-branch $ <really screw up the branch> $ git add . $ git commit -a -m "Screwed up" $ git checkout master $ git branch -D topic-branch ////push $ git push or git push orgin master
git diff跟踪wd和index的不同
git diff --staged跟踪index和last committed的不同
It’s important to note that the fetch command pulls the data to your
local repository — it doesn’t automatically merge it with any of your work or modify what you’re
currently working on. You have to merge it manually into your work when you’re ready.
To see which branches
are already merged into the branch you’re on, you can run git branch --merged:
To see all the branches that contain work you haven’t yet merged in, you can run git branch --no-
merged:
If you
didn’t want it to be called serverfix on the remote, you could instead run git push origin
serverfix:awesomebranch to push your local serverfix branch to the awesomebranch branch on
the remote project.