CONFIGURE
1 2 3
| git config --global user.name "David Beckwith"
git config --global user.email "dbitsolutions@gmail.com" |
或者
| git config --global alias.co checkout |
- 去忽略空白 (Ruby is whitespace insensitive)
| git config --global apply.whitespace nowarn |
1 2 3 4 5 6 7
| gb = git branch gba = git branch -a gc = git commit -v gd = git diff | mate gl = git pull gp = git push gst = git status |
在根目录下增加一个叫 .gitignore 的文件,并且增加你想ignore的文件:
1 2 3
| *.log db/schema.rb db/schema.sql |
Git自动ignore空目录。如果你想包含log目录,但是想ignore里面的所有文件,首先在.gitignore文件里加 log/* , 然后在这个空目录下再添加一个空的 .gitignore 文件。
- add新文件以及所有change到git index *
| git commit -m "First import" |
| git commit -m "This is the message describing the commit" |
- -a是代表add,把所有的change加到git index里然后再commit *
- TO VIEW A LOG OF YOUR COMMITS WITH A GRAPH TO SHOW THE EXTENT OF THE CHANGES *
- TO HAVE PAGINATION WHEN VIEWING THE LOG FILE USE THE -v OPTION *
- TO VISUALIZE YOUR CHANGES *
| git branch [name of your new branch] |
- TO VIEW ALL OF THE EXISTING BRANCHES *
- TO VIEW A LIST OF ALL BRANCHES *
- TO SWITCH TO ANOTHER BRANCH *
The state of your file system will change after executing this command.
| git checkout [name of the branch you want to switch to] |
OR
| git co [name of the branch you want to switch to] |
- TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH (WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND *
- TO MERGE YOUR NEW BRANCH INTO THE MASTER BRANCH *
First, switch back to the master branch:
Check to see what changes you’re about to merge together, compare the two branches:
If you’re in a branch that’s not the xyz branch and want to merge the xyz branch into it:
- TO REVERT YOUR CHANGES to before the merge. *
| git reset --hard ORIG_HEAD |
- TO RESOLVE CONFLICTS just edit your file. *
Remove the markings, add the file, then commit.
- TO CREATE A BRANCH AND SWITCH TO THE BRANCH IN ONE MOVE: *
| git checkout -b [name of new branch] |
- TO CREATE A “CLIPBOARD” or “STASH” OF CHANGES THAT ARE NOT YET COMMITED (SO THAT YOU CAN SWITCH TO ANOTHER BRANCH IN THE MIDDLE OF YOUR CHANGES.), CREATE A STASH.*
| git stash "Put a message here to remind you of what you're saving to the clipboard" |
- TO SWITCH AWAY FROM THE CURRENT BRANCH *
| git co [branch you want to switch to] |
- Do whatever Then switch back to the stashed branch *
| git co [the stashed branch] |
- TO VIEW THE LIST OF STASHES *
- TO LOAD BACK THE “CLIPBOARD” OR “STASH” *
Now you can continue to work where you were previously.
- TO DELETE A BRANCH THAT IS NOT USED ANYMORE, but already merged into the current branch. (TO CLEAN UP)*
| git branch -d [name of branch you want to delete] |
- TO DELETE AN UNMERGED BRANCH *
| git branch -D [name of branch you want to delete] |
- TO DELETE THE STASH. (ERASE THE “CLIPBOARD” FROM MEMORY)*
- TO SET UP YOUR REPOSITORY FOR SHARING ON A CENTRAL SERVER *
Copy up your repository. e.g.:
| scp -r my_project deploy@yourbox.com:my_project |
Move your files on the remote server to /var/git/my_project For security make the owner of this project git On the repository server:
| sudo chown -R git:git my_project |
Then (for security) restrict the “deploy” user to doing git-related things in /etc/passwd with a git-shell.
- TO CHECK OUT THE GIT REPOSITORY TO YOUR LOCALHOST. ON YOUR LOCAL HOST DO THIS:*
| git clone git@yourbox.com:/var/git/my_project |
- TO SEE SOME INFO ABOUT THE REPOSITORY THAT WILL TELL YOU WHICH REPOSITORY IS THE MASTER AND WHICH IS THE SLAVE:*
By virtue of having cloned the remote repository, your local repository becomes the slave and will track and synchronize with the remote master branch.
- TO UPDATE YOUR LOCAL BRANCH FROM THE REMOTE SERVER: *
- TO GET A COPY OF THE ENTIRE REMOTE REPOSITORY (e.g. a repository named “laptop”) WITHOUT MERGING THEM INTO YOUR LOCAL BRANCHES USE FETCH*
- TO MERGE TWO LOCAL BRANCHES (ie. your local xyz branch with your local master branch) USE MERGE *
This merged the (already copied laptop repository’s xyz branch) with the current branch you’re sitting in.
- TO MERGE THE REMOTE BRANCH WITH YOUR LOCAL BRANCH THAT YOU ARE SITTING IN USE PULL
TO ADD LOCAL KNOWLEDGE (TO YOUR LOCAL REPOSITORY) OF A 2ND REMOTE REPOSITORY, LIKE YOUR LAPTOP*
| git remote add laptop duo2book.local:repos/m_project |
where ’’‘laptop’’” is the name of the remote repository and ”’‘duo2book.local’’” is the name of the remote machine.
- TO VIEW META INFORMATION ABOUT THAT REMOTE REPOSITORY *
- TO PUSH A COMMITTED LOCAL CHANGE OF THE xyz BRANCH TO THE REMOTE laptop BRANCH *
*TO CREATE A TRACKING BRANCH (A SLAVE BRANCH). * Ie. to link a local branch to a remote branch:
| git branch --track local_branch remote_branch |
- NOW IF YOU’RE SITTING IN THE LOCAL TRACKING BRANCH, TO PULL YOU DON’T NEED TO SPECIFY THE REMOTE TRACKING BRANCH:*
Note: You can track(link) different local branches to different remote machines. For example, you can track your friend’s “upgrade” branch with your “bobs_upgrade” branch, and simultaneously you can track the origin’s “master” branch (of your main webserver) with your local “master” branch.
By convention, ‘origin’ is the local name given to the remote centralized server which is the way SVN is usually set up on a remote server.
- TO SEE WHICH LOCAL BRANCHES ARE TRACKING A REMOTE BRANCH:*
TO WORK WITH AN SVN REPOSITORY BUT WORK WITH GIT LOCALLY:
| git-svn clone [http location of an svn repository] |
Now you can work with the checked out directory as though it was a git repository. (cuz it is)
TO PUSH (COMMIT) CHANGES TO THE REMOTE SERVER
- TO UPDATE YOUR LOCAL REPOSITORY FROM THE SVN REPOSITORY*
NOTE: make sure you have your perl bindings to your local svn installation.
I screwed up, how do I reset my checkout?
阅读(2293) | 评论(0) | 转发(0) |