git reference

来源:互联网 发布:java的方法名命名规则 编辑:程序博客网 时间:2024/04/29 19:24

1. It is always recommended to use git command line rather than GUI.(eg. do the commit, update, push and whatever via git command line)


2. How to remove (null) in "git remote"?

Edit the .git/config file (".git" is a subdirectory in your project's directory).


3. Basic usage of git command?

http://www.mceiba.com/tool/git-cheat-sheet.html

http://www.coder4.com/archives/2642


4. What if you encounter "non-fast-forward" error when trying to push?

try "git pull" to fetch and merge remote copy.


5. What if you encounter "You asked me to pull without telling me which branch you want to merge with" when executing "git pull"?

edit the .git/config file and add the following:

[branch "master"]
        remote = origin
        merge = refs/heads/master


6. What if you encounter conflicts when trying to merge(or pull)?

You should manually merge the conflicts in the files. Then commit and push.

If you do not merge the conflicts, you may encounter problem 7.

You can also "git push --force" to force push to remote repository however it is not recommended.


7. What if you encounter "cannot be opened because the project file cannot be parsed." when opening the .xcodeproj file?

a) right click the .xcodeproj and "Show package contents"

b) edit the "project.pbxproj"

c) delete the lines containing <<<<<<<,======,>>>>>>

d) save and exit

e) reopen the .xcodeproj file


8. How to override the local project with remote copy?

a) remove local project folder

b) git clone https://github.com/<user_name>/<project_name>.git

9. How to add git version control to a local project? How to push it to an existing github remote repository?

a) cd <project_folder>

b) git init

c) git add .

d) git commit -a -m "initial commit"

e) git remote add origin https://github.com/<user_name>/<project_name>.git

f) vim .git/config and add the following lines:

[branch "master"]
        remote = origin
        merge = refs/heads/master

g) git push --force


10. How to set ignore files in git for xcode projects?

a) vim [project_dir]/.gitignore

# Xcode ############*.mode1*.mode1v3*.mode2*.mode2v3*.mode1v3*.pbxuser*.perspective *.perspectivev3*.pyc *~.nib/build/**.xcworkspace**.xcuserdata*# Textmate -############*.tm_build_errors# Subversion############.svn# OS generated files #######################.DS_Store?ehthumbs.dbIcon?Thumbs.db# Packages ############## it's better to unpack these files and commit the raw source# git has its own built in compression methods*.7z*.dmg*.gz*.iso*.jar*.rar*.tar*.zip# Logs and databases #######################*.log*.sql*.sqlite# Misc #######################*.swp


11. How to checkout git submodules?

When you checkout a git project using git clone, chances are that some project files are not checked out. These files could be submodule(s) that are linked to another git project. You can using the following command to checkout the submodules.

a) 1st way:

git clone --recursive [???.git]

b) 2nd way:

git clone [???.git]

git submodule update --init --recursive



12. How to revert a commit already pushed to a remote repository?

http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html


13. How to create a branch locally and remotely?

a) create a local branch

git branch <branchname> 

b) switch to the branch(set the current working branch)

git checkout <branchname>

c) push the local branch to the server and create a remote branch

git push origin <local-branchname>:<remote-branchname>


13. How to temporarily save your changes without commit?

git stash


14. How to unstash?

git stash pop


15. How to delete a branch locally and remotely?

Locally,

git branch -D <branch>

Remotely(git 1.7 or later),

git push origin --delete <branch>


16. How to merge the current branch with another?

first, you need to switch the working branch to the current branch by git checkout <branch>

then, git merge <another-branch>

last, git push 


17. How to revert uncommitted changes?

# remove changes to modified files(staged)

git checkout <file>

# remove changes to modified files(uncommited and staged)

git reset <file>

# remove all untracked files and directories

git clean -fd

# inspect all untracked files and directories(before removal)

git clean -nd


18. How to resolve "Your local changes to the following files would be overwritten by merge. Please, commit your changes or stash them before you can merge." after you do a "git pull"?

first you need to stash the local changes by "git stash".

"git pull"

"git stash pop" to unstash

"git add"

"git commit -m "




原创粉丝点击