GIT / Uncategorized

Real time scenarios on GIT

git clone https://github.com/beingsagir/play-java-spring-data-jpa.git
git add -all : add all files new and modified locally

git add -A && git commit -m “Comment formatting, 24 hour cache loader, api/contact.”
add all files new and modified locally, commit them locally.

How to see what has changed before actually doing commit

# show differences between index and working tree
# that is, changes you haven't staged to commit
git diff [filename]
# show differences between current commit and index
# that is, what you're about to commit
git diff --cached [filename]
# show differences between current commit and working tree
git diff HEAD [filename]

FIRST PUSH SEQUENCE

git status
git diff
git status
git pull
git stash
git pull
git stash list
git apply stash@{0}
git stash list
git stash apply stash@{0}
git push -u origin master
git status
git push -u origin master
exit
cd /home/user/projects/******-server
git status
ls
get status
git status
git log
git push -u origin master
git push -u origin master git_tracing=2
clear
git push -u origin master

SECOND PUSH SEQUENCE

git status
git add –all
git status
git add -all -v
git add –all -v
git add -i
git status
git stash list
clear
git add -A && git commit -m “Comment formatting, 24 hour cache loader, api/contact.”
history
git add -A && git commit -m “Resolved Conflicts in conf/routes”
git push -u origin master
git status
git status remote
git status remote origin
clear
git remote show origin
cd /home/user/projects/******-server
git remote show origin

git pull

remote: Counting objects: 8, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 6), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From https://gitlab.com/*****/*****-server
ecc5a5f..32ce420  master     -> origin/master
Auto-merging conf/routes
CONFLICT (content): Merge conflict in conf/routes
Automatic merge failed; fix conflicts and then commit the result.

git status

In case of CONFLICTS resolve conflicts, first, then do a push.

To resolve conflicts, first determine the files under conflict, by issuing git status or

git log –merge -p conf/routes

Resolve your conflicts in any editor or iDEA

git add -A && git commit -m “Resolved Conflicts in conf/routes” : Perform a local commit

git push -u origin master

git config merge.conflictstyle diff3
git status
git diff
git status
git diff
git status
git diff app/controllers/users/UserController.java
git diff HEAD app/controllers/users/UserController.java
clear
git status

git add -A && git commit -m “Comment formatting, 24 hour cache loader, api/contact.”

before doing a push check always ensure to do a pull

********************************************************************

STASHING

git pull
676  git stash –help
677  git log
678  git stash list
679  git stash save “Tests included for BadRequest, Exception Handling in fetchstatesforcountries”
680  git show
681  clear
682  git stash list

user@sys204:~/projects/datacaptive-server$ git stash list
stash@{0}: On master: Tests included for BadRequest, Exception Handling in fetchstatesforcountries
stash@{1}: WIP on master: 8829572 API Contracts, to return JSON responses. sabhi
683  git pull
684  git apply stash@{0}
685  git stash apply stash@{0}

************************************************************

Determine your remote repository

user@user-HP-Compaq-8100-Elite-SFF-PC:~/projects/*****-server-1$ git config --get remote.origin.url
https://gitlab.com/***********ivedevs/*****-server.git

git remote show origin

—————————-

In certain cases you need to checkout a branch from a remote

git clone https://github.com/matthiasn/sse-chat.git –branch 130707-kibana-demo

 

*******************************************************

git log –graph –oneline –decorate –all

In case of comparing what your local has and what has been done on remote, it is first required to fetch the references of your remote on to your local

user@sys204:~/projects/******-server$ git fetch
Username for ‘https://gitlab.com’: ******@******.com
Password for ‘https://******@******.@*****.com’:
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From https://gitlab.com/*********/*****
7950246..666039a  master     -> origin/master
user@sys204:~/projects/********-server$

 

After doing a fetch, issuing a log would still result in local changes and not depicting remote changes.

user@sys204:~/projects/******-server$ git log

user@sys204:~/projects/******-server$ git log -all : displays the fetch references and the local refs

user@sys204:~/projects/******-server$ git log origin/master : displays the fetch references and the local refs

 

****************************************

Rebasing:

user@sys204:~/projects/datacaptive-server$ git status
On branch master
Your branch and ‘origin/master’ have diverged,
and have 1 and 1 different commit each, respectively.
(use “git pull” to merge the remote branch into yours)
Changes not staged for commit:
(use “git add <file>…” to update what will be committed)
(use “git checkout — <file>…” to discard changes in working directory)

modified:   app/controllers/api/ContactsApiController.java
modified:   app/utils/CSVUtils.java
modified:   app/utils/SelectBuilder.java
modified:   test/controllers/api/ContactsApiControllerTest.java

Untracked files:
(use “git add <file>…” to include in what will be committed)

app/models/api/BasePackage.java
app/models/api/CallingPackage.java
app/models/api/CompleteContactPackage.java
app/models/api/EmailLeadPackage.java
app/models/api/MailPackage.java
app/models/api/Person.java
app/models/api/test/

no changes added to commit (use “git add” and/or “git commit -a”)
user@sys204:~/projects/datacaptive-server$ git stash save “Package Factory in Place with Abstraction and Inheritance”
Saved working directory and index state On master: Package Factory in Place with Abstraction and Inheritance
HEAD is now at d8f3827 Bad Request Tests
user@sys204:~/projects/datacaptive-server$ git stash list
stash@{0}: On master: Package Factory in Place with Abstraction and Inheritance
stash@{1}: On master: Tests included for BadRequest, Exception Handling in fetchstatesforcountries
stash@{2}: WIP on master: 8829572 API Contracts, to return JSON responses. sabhi
user@sys204:~/projects/datacaptive-server$ git rebase
First, rewinding head to replay your work on top of it…
Applying: Bad Request Tests
Using index info to reconstruct a base tree…
M    app/controllers/api/ContactsApiController.java
M    conf/application.conf
Falling back to patching base and 3-way merge…
Auto-merging conf/application.conf
Auto-merging app/controllers/api/ContactsApiController.java
user@sys204:~/projects/datacaptive-server$ git stash apply stash@{0}
Auto-merging app/controllers/api/ContactsApiController.java
CONFLICT (content): Merge conflict in app/controllers/api/ContactsApiController.java

 

****************************************

At times there might be ignored files which would have been indexed and committed to the repo, and later realized that the files should not have been there.

Your .gitignore is working, but it still tracks the files because they were already in the index.

To stop this you have to do : git rm -r --cached .idea/

When you commit the .idea/ directory will be removed from your git repository and the following commits will ignore the .idea/ directory.

PS: You could use .idea/ instead of .idea/* to ignore a directory. You can find more info about the patterns on the .gitignore man page.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *