john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

eclipse git ssh egit

JUST GIT
every commit is identified by a SHA (40 characters)


sudo apt-get install git-core
git config --list
git config --global user.name "John Pfeiffer"
git config --global user.email "admin@john-pfeiffer.com"
git config --list


cd /home/ubuntu/Desktop/docs/workspace
git init


- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
~/.ssh is where you keep your ssh keys

vi ~/.ssh/config

Host first.gitserver.com
  HostName first.gitserver.com
  User git
  IdentityFile ~/.ssh/id_rsa_privateserve

Host github.com-foupfeiffer
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_rsa


git clone https://github.com/username/reponame
(don't be surprised if you're prompted to login again)


- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The easy way (just java files)

nano .gitignore
  *
  !*.java



- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The hard way... at the root of the git repo create a text file .gitignore

*.class

# Package Files #
*.jar
*.war
*.ear

# maven build artifacts #
target/

*/target/*

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
THE BEST WAY TO MERGE (when git pull gives you the unfortunate news...)

Updating 7052d46..9c531c7
error: Your local changes to the following files would be overwritten by merge:
        project/src/main/java/com/Example.java

Please, commit your changes or stash them before you can merge.
Aborting


git stash       //now your current local stuff is saved
git pull        //now your local repo reflects the remote

(for fun at this point you could go into Eclipse, refresh, run maven/ant clean test build...)

git stash pop       //auto merge your changes back into your local repo

Now look for any errors where a merge must be fixed/handled manually

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
to remove previous mistakes

git rm *.class -f

(forces the removal, then do a git commit and push)


OR

git stash

git reset --hard HEAD

- - - - - - - - - - - - - - - - - - - -

git diff Example.java  //shows the changes between the local file and the committed repo file
git add *.java
git commit -m "initialize repo"
git status

git ls-files
git ls-files  file_name --error-unmatch
git ls-files | wc -l
git ls-tree -r --name-only HEAD
git ls-tree -r --name-only MASTER | wc -l

git reflog
git log             //see commit history (reverse chronological order)
git log --stat      //see abbreviated list/stats of recent commits
git log -p -2       //see the commit history including DIFF for the last 2 items


git log --pretty=oneline        //shows commits on one line each
git log --pretty=format:"%h - %an, %ar : %s"


gitk            //GUI for git commit history

//git pull
//git push

- - - - - - - - - - - - - - - - - - - - - - - -
git clone user@repository.domain.com:projectname.git

git remote show origin (discover the url, name, and branches)
(or git remote -v)

    git log
    git log -- filename.txt
    git whatchanged since until -- filename.txt
    git help


- - - - - - - - - - - - - - - - - - - - - - - -
REMOVING LOCAL COPIES BEFORE DOING A GIT PULL

1) git checkout -- .

checkout the latest version and overwrite old files not affect deleted, renamed, or new files

2a) git stash save --keep-index
2b) git stash drop

stash uncommitted files, then drops them entirely.
Good if there are committed changes to keep and uncommitted/unstaged changes to discard

3)git reset --hard

Wipes out everything since the last commit, including file renames, deletions, and additions

4) git clean ?

- - - - - - - - - - - - - - - - - - - - - - - -

git mv is merely a convenience method. git does not "track" renames
(that is, it can detect them, but they are not recorded as an operation like an add or remove)

instead just use "git add" and "git rm"  (and git log --follow if you want to see history)

- - - - - - - - - - - - - - - - - - - - - - - -
CREATE, INITIALIZE, AND PUSH TO ORIGIN MASTER A NEW REPO

mkdir /workspace/TEMP (master)
cd /workspace/TEMP
git init
touch empty-file-initialize-repo.txt
git add empty-file-initialize-repo.txt
git commit -m "empty-file-initialize-repo"
    [master (root-commit) 0df7d96] starting the repo
    0 files changed
    create mode 100644 temp.txt

git remote add origin git@server.com:projectname-common.git
git push origin master
    Initialized empty Git repository in /ebs/data/gitosis/projectname-common.git/
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 224 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@server.com:projectname-common.git
    * [new branch]      master -> master

//NOW THE "MAIN" server has the new repo

cd /workspace

git clone git@server.com:projectname-common.git
    Cloning into 'projectname-common'...
    Receiving objects: 100% (3/3), done.
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)

//CLEANUP THE TEMPORARY BOOTSTRAP REPO
rm -rf /workspace/TEMP


- - - - - - - - - - - - - - - - - - - - - - - -
PREREQUISITE

Window  -> Preferences ->  General ->  Network Connections ->  SSH2

Key Management (tab) -> Generate RSA Key

"You can paste this public key into the remote authorized_keys file"

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCBOKhzHKQMdxZxf5d4qpazvt/CGxERmRain0c7rLJBYI4wcVk0nUpKFH/d3Tj9L1f+CjsScHXBK9LI77YAlYOVX9gfEZskwEdJats1Cup7VN4NLbzlxP0gGB9HTf1B+ZKC8VRG+Z8DxAok70IESpWV9RKLehHlpQsEieitq7zyaw== RSA-1024

Save Private Key! (e.g. becomes ~/.ssh/id_rsa  and ~/.ssh/id_rsa.pub)

- - - - - - - - - - - - - - - - - - - - - - - -

EGit (eclipse git)
Help -> Install New Software -> Available Software Sites preferences (filter for git)
http://download.eclipse.org/egit/updates
(This actually is already included in Eclipse 3.7+)

Work with: --All Available Sites--
Wait for all of the Names and versions to appear in the listing...

Eclipse EGit Feature (Incubation)
Eclipse JGit Feature (Incubation)

After Eclipse Restarts there is a new option available: File -> Import -> Git -> Projects from Git -> URI

git@heroku.com:glowing-wind-3935.git

Next -> (yes accept the fingerprint) -> (Next to accept the "master" branch)

/home/ubuntu/git/glowing-wind-3935
Initial branch: master
Remote name: origin

Import as a general Project

Team -> Add             //on the project node adds all files
Team -> Commit          //commits changes to the local repository
Team -> Branch          //create and switch between branches
Team -> Push                //push changes to a remote repository
Team -> Tag             //manage tags



Note best practice:

PROJECTNAME/src/main/java/com/example/controller  along with model and service
PROJECTNAME/src/main/resources
PROJECTNAME/src/main/webapp (includes META-INF, WEB-INF, index.jsp)


- - - - - - - - - - - - - - - - - - - - - - - -

  • « return namedtuple versus dictionary performance
  • string substring slice hashing crc md5 sha1 »

Published

Mar 25, 2013

Category

java

~807 words

Tags

  • eclipse 22
  • egit 1
  • git 8
  • java 252
  • ssh 14