# .gitignore reference: https://github.com/github/gitignore
--------------------------------------------------------------
before push:
1. genenrate ssh keys in local - id_rsa&id_rsa.pub;
ssh-keygen -t rsa -C "164335424@qq.com"
# which will generate a directory in /home/eason/ named .ssh.
2. generate ssh key in GitHub by copying the content of id_rsa.pub in .ssh.
---------------------
basic operations:
git init: set the pwd as a git-control repository.
git add <filename> / git commit <filename> -m "xxx" : to stage and commit.
git status: to report all the changes in working directory/ stage / repository.
local operations:
1. git log / git reflog
git log: used to print out the information of the recent modifications which have been commited. (version id, modification info etc.)
git reflog: if you want to return your working directory to <ver_id> after you've already closed the git, you can reopen the git and use 'git reflog' to print out the information of the modification you make and find the target commit id.
2. git reset --hard HEAD^ / git reset --hard <ver_id>
reset the working directory to <ver_id> version.
3. git checkout -- <filename> && git reset HEAD <filename>
git checkout: used to change the content within working directory to which within temporary stage or master branch's HEAD. (This operation changes working directory.)
git reset HEAD <filename>: used to unstage the modification to <filename>. (This operation changes the temporary stage.)
4. git diff HEAD -- <filename> / git diff <filename>
used to find out the differences of <filename>'s content in working directory and <filename>'s content in repository.
5. git rm <filename> / git checkout -- <filename>
after you delete a file in working directory, you can use 'git rm' to delete the file in repository.
Or, you can use "git checkout -- " to restore the deleted file from repository.
Remote operations:
1. git remote add origin <remote GitHub repository's name>
link the local repository to the empty remote repository you created on GitHub, where parameter <origin> will represent the remote repository in further local use.
2. git push -u origin master
push the content of local repository <master> to remote repository <origin>, since now the <origin> represents the remote repository as mentioned above.
the <-u> parameter is used to link the local master branch to the remote master branch,
'local master branch' <-----> 'remote master branch'
this will simplify the further use of commands. For futher 'push', you only need to type in,
$ git push origin master
3. git branch <branch_name> / git branch / git branch -d <branch_name>
create a branch named <branch_name>, look up all branches, delete a branch named <branch_name>
4. git checkout <branch_name> / git checkout -b <branch_name>
change the current branch to the branch named <branch_name>;
with <-b>, it means firstly create a branch named <branch_name>, and then make the newly-created branch the current branch.
5. git merge <branch_name>
merge the specified branch named <branch_name> to current branch.
MERGE CONFLICT:
- Commit a change on 'feature1' branch.
- Back to 'master' branch, commit another change on the same file.
- try to git merge 'feature' branch to 'master' branch. merge conflict happens.
- then both changes on the file will be showed in that file,
...(Original content of the file)
<<<<<<<<HEAD
...( changes made in master branch)
--------------
--------------
...(changes made in feature1)
>>>>>>>>feature1
So now we're asked by Git to decide the final version of the change of that file by manually delete one version of change and let the decided one remains. We can see that the Git Bash command line has entered into a branch status (master|MERGING), which indicates us to decide and add&commit the final version. Then the branch status will be back to (master).