Git basic

1. solve conflict

senario:

  Adam checked out master branch,

  then Bob checked out master branch,

  then Adam modify a file, commit and push,

  then Bob modify the same file,

  then Bob need to commit, then pull, then manually resolve the conflit, then commit again, then push.

2. ignore a tracking file, remove from remote

http://stackoverflow.com/questions/9237345/how-do-i-ignore-pycharm-configuration-files-in-a-git-repository

for single file

git rm --cached [filename]

for folder

git rm --cached -r [folder]

 3. save password and username

http://stackoverflow.com/questions/11403407/git-asks-for-username-everytime-i-push

git config credential.helper store
git push http://example.com/repo.git

 4. compare file with last commit

git diff HEAD [filename]

 5. revert file to last commit

http://stackoverflow.com/questions/692246/undo-working-copy-modifications-of-one-file-in-git

git checkout -- [filename]

 6. only add tracking file

git add -u

 7. download project

git remote add origin https://github.com/xxx.git
git pull origin master

 8. change origin (in case like repo name changed)

check remote 

git remote -v

change remote origin

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

 9. undo git add

git reset <file>

http://stackoverflow.com/questions/348170/how-to-undo-git-add-before-commit

原文地址:https://www.cnblogs.com/phoenix13suns/p/4620646.html