Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Git commands
- git clone https://github.com/salamander2/leds
- git fetch --all [no repository argument]
- git pull ____ does a "git fetch" then a "git merge"
- http://www.answering-islam.org/authors/toler/abraham_kaaba.html
- gitk # starts a GUI !!!
- ================= SETUP ===========================
- cd to the location desired (probably above the package folder)
- git init
- git remote add origin ssh://git@github.com/salamander2/Display-Array-Java
- #use set-url to update/change the url (ie from HTTPS to SSH)
- git remote set-url origin ssh://git@github.com/salamander2/Display-Array-Java ## NO, NOT THIS ONE
- git remote -v # list the settings for git remote
- git remote show origin # this works better
- eval `ssh-agent -s`
- ssh-add ~/.ssh/id_rsa_git.ssh # don't use default SSH-key (id.rsa)
- ssh -T git@github.com #test conection
- git pull origin master # get the local branch synced to the remote one.
- *** For some reason this doesn't always work.
- HTTP version:
- using: git clone https://github.com/salamander2/myRPGGame
- results in .git/config having these lines:
- [remote "origin"]
- url = https://github.com/salamander2/myRPGGame
- but this:
- git remote set-url origin git@github.com/salamander2/myRPGGame
- ends up with:
- [remote "origin"]
- url = git@github.com/salamander2/myRPGGame
- WHICH DOES NOT WORK FOR pit push origin master !!!
- Copy the .git/config file from some other project
- ******************************************
- OR:
- git remote add origin https://github.com/RaiderRobotics/FRC-LCD-Display.git
- git push -u origin master #using some user
- ********************************************
- #Fixing the author and email used for commits:
- git config --global user.name "Michael Harwood"
- git config --global user.email you@example.com
- git config --global --list
- git commit --amend --reset-author
- ## This is for HTTP access so that you don't have to keep entering username and password
- git config --global credential.helper cache
- git config --global credential.helper 'cache --timeout=3600'
- # Set the cache to timeout after 1 hour (setting is in seconds)
- git remote -v # show current connection
- git remote show origin # this works better than the previous line
- ================= COMMITS ========================
- git status
- git add filename
- get reset # This will undo the git add command
- get rm filename #only if you need to delete a file
- ex
- git commit
- git commit -a #this does the add & rm & commit in one step
- OR
- git fetch
- git diff origin/master
- git push origin master
- git pull origin master
- ================ LOG DISPLAY ==========================
- git log --graph --decorate --abbrev-commit --all # use this to compare local and remote repos.
- # you need --decorate
- http://www.answering-islam.org/authors/toler/abraham_kaaba.html
- git log --graph --decorate --abbrev-commit --all --pretty=medium
- #follow only one file:
- git log -- filename
- http://www.answering-islam.org/authors/toler/abraham_kaaba.html
- #show changes for one file:
- git log -p filename
- ================ TAGS ==============================
- git tag -a tagname HEAD # This creates an annotated tag (a more permanent version)
- (then enter a tag message)
- eg. git tag -a v2.0
- git tag -l -n2 # list tags with 2 lines of comments
- git log --decorate # this lists the tags along with the commits
- git show v2.0 # this lists the comment for this ta
- TO PUSH TAGS you have to do the following ... add --tag
- (Annotated) TAGS automatically show up as releases in GitHub
- git push -u --tag origin master
- =============== DIFF ===================
- git diff HEAD^ compares the current files with the previous version.
- > git status
- On branch master
- Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
- modified: hsa2/ConsoleCanvas.java
- http://www.answering-islam.org/authors/toler/abraham_kaaba.html
- renamed: hsa2/Console.java -> hsa2/GraphicsConsole.java
- > git diff HEAD^ -- hsa2/ConsoleCanvas.java
- # This command, above, shows the differences in this file only.
- ================ MERGING LOCAL & REMOTE ============================
- (when Git cannot merge automatically)
- git mergetool
- OR
- git mergetool -t meld
- You'll see 3 wndows in MELD:
- * The local branch
- * The current version that you are merging into
- * The other (or “remote”) version
- Make the centre window look like the one you want. Then save it.
- You normally want the local version to also look like the middle version. That should eliminate the creation of annoying .orig files
- Then use git status, add, commit, push.
- ================= BRANCHES =======================
- git remote show origin # shows branches too
- git branch -a # list all branches (local and remote)
- git checkout branchname # switch to branch
- git branch # list local branches and show which is active
- git branch newname # create a new branch
- git branch -d branchname # delete local branch
- git push origin :branchname # delete this branch upstream
- OR
- git push origin --delete branchname
- git
- #rename a branch
- git branch -m old_branch new_branch # Rename branch locally
- OR
- git branch -m new_branch # rename currently checked out branch
- git push origin :old_branch # Delete the old branch
- git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
- OR
- git push -u origin new_branch # new branch is the current branch that you're on
- OR
- git push origin # this will default to pushing the current branch to the same named remote.
- ================ MERGING BRANCHES =================
- You can run your tests, make sure the hotfix is what you want, and merge it back into your master branch to deploy to production. You do this with the git merge command:
- git checkout master
- git merge hotfix
- ================ FIXING ERRORS ====================
- ---------------------------------- UNDOING MOST RECENT COMMIT ------------------------
- git reset --hard HEAD^ # HEAD^ is the parent of the current commit.
- OR
- git revert HEAD^ # this creates a NEW commit that undoes the previous one.
- THEN
- git push --force origin master #force github to also go back to the previous commit
- --------------------------------- Fixing pulling wrong branch! ----------------------------
- *** If you're in a different branch and run "git pull origin master" it will MERGE the master branch into the current branch!!!
- To undo this:
- (1) run git reflog
- git reflog
- 46d3be4 HEAD@{0}: pull origin master: Merge made by the 'recursive' strategy.
- 346f2d2 HEAD@{1}: commit: renamed ArrayGame.java to UserArrayGame.java
- ec0eb50 HEAD@{2}: commit: First working version of this branch. Using the MouseObserver pattern.
- 00ba00d HEAD@{3}: checkout: moving from master to Observer-pattern
- 00ba00d HEAD@{4}: commit (merge): Fixed Merge branch 'master' of github.com:salamander2/Display-Array-Java
- 3ba071e HEAD@{5}: commit (initial): First commit
- (2) find the previous header id, and run git reset :
- git reset --hard 346f2d2
- HEAD is now at 346f2d2 renamed ArrayGame.java to UserArrayGame.java
- ===============================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement