Brief introduction
Before learning is
Git
time to do a note to see that Liao Xuefeng of Git tutorial , no matter the holiday, so remember to sort out, to be sent to the csdn.
Day1
1, initialize a Git repository:
- Create a new folder, right-click on the selected
Git Bash Here
inputgit init
command.
2, add files to the Git repository, in two steps:
- The first step in using the command
git add <文件名>
, pay attention, can be used repeatedly to add multiple files. - The second step uses the command
git commit -m "注释信息"
to complete the addition.
3, the modified file operations:
- Use the command
git status
to view the status of the work area. - Use the command
git diff
to view the content. - Before submitting modify and add files to the same steps Git repository.
4, version rollback
- Use
git log
command to view your history in order to determine which version you want to go back retreated. - Use the
git reflog
View command history in order to determine what you want to return to a future version. - Use
git reset --hard HEAD^
fall back to the previous version,HEAD^
on behalf of the previous version,HEAD^^
the previous version of the delegates. - Use
git reset --hard <提交的id号>
fall back to a specific version.
5, understand the staging area
git add
Command is actually all modifications to be submitted into the staging area (Stage), then executegit commit
the command can be one-time submission of all changes to the temporary area branch.
Day2
1, modify management
- Each modification, if not
git add
command code into the staging area, thencommit
it will not submit this amendment. - Modify the file, but did not add to the staging area, it can be used
git checkout -- <文件名>
to discard modify the workspace. - Modify the document, while add to the staging area, the first step with a command
git reset HEAD <文件名>
to canceladd
, and thengit checkout -- <文件名>
dropped to modify the workspace.
2, delete the file
- Use
rm <文件名>
the command to delete a file, you sure you want to delete it with the commandgit rm <文件名>
to delete, and with thegit commit -m "备注信息"
submission. - Mistakenly deleted can be
git checkout -- <文件名>
restored to the latest version. git checkout
In fact, the workspace is a replacement version with the version in the repository, regardless of the workspace is modified or deleted, can be "a key to restore."
3, add a remote library
- Create a new folder, use the
git init
command, making it a local warehouse. - Open Git, run in the local repository
git remote add origin <你的 github 上的一个远程库的地址>
, for example:[email protected]:yueyueNSYW/learngit.git
so that you can remotely associated with the local library and the library again. - Use
git push -u origin master
the command, Git will put the localmaster
branch of remote content push a newmaster
branch, but also the localmaster
branch and remotemaster
can be simplified command associate branch, after such a push or pull. - After modifying the files in the local library and
commit
later, you can use thegit push origin master
command to the localmaster
last modified branch pushed to GitHub .
Day3
1, from a remote library clones
- Github now create a new project, to build a consistent folder with the project name locally, using the
git init
command to make it a local library, and then use thegit clone <你的 github 上的这个远程库的地址>
command to the remote library clones to the local library. - View branch:
git branch
- Create a branch:
git branch <分支名>
- Switching branches:
git checkout <分支名>
- Create a + to switch branches:
git checkout -b <分支名>
- Merging a branch to the current branch:
git merge <分支名>
- Deleted branches
git branch -d <分支名>
orgit branch -D <分支名>
(force deletion)