Objective: Set up Marcus's GIT master as a remote repository
git remote add marcus https://github.com/mmoyses/jboss-as.git
Objective: Sync my branch with Marcus on a regular basis.
git fetch marcus; git merge marcus/master --ff-only
Objective: Bungled my master. Need to recreate my master from jboss-as upstream master.
Solution #1:
git reset --hard upstream/master
Example:
anil@localhost:~/as7/jboss-as$ git reset --hard upstream/master HEAD is now at 328151e changed jaas to security-domains
Solution #2:
git branch -D master git fetch upstream git checkout upstream/master git checkout -b master
Example:
anil@localhost:~/as7/jboss-as$ git branch -D master Deleted branch master (was 4340a3b). anil@localhost:~/as7/jboss-as$ git fetch upstream remote: Counting objects: 56, done. remote: Compressing objects: 100% (22/22), done. remote: Total 44 (delta 8), reused 0 (delta 0) Unpacking objects: 100% (44/44), done. From git://github.com/jbossas/jboss-as b3e90b9..328151e master -> upstream/master anil@localhost:~/as7/jboss-as$ git checkout upstream/master Previous HEAD position was 1504538... sync HEAD is now at 328151e... changed jaas to security-domains anil@localhost:~/as7/jboss-as$ git checkout -b master Switched to a new branch 'master' anil@localhost:~/as7/jboss-as$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .metadata/ nothing added to commit but untracked files present (use "git add" to track)
Objective Your origin (fork of upstream jboss-as) is totally screwed up
Go to github dashboard and delete the repository.
After that, fork the upstream and follow the http://community.jboss.org/wiki/HackingonAS7 guide.
Objective: Cherry pick one of Marcus's commits
git cherry-pick b4e04f52046cad2687d60348bad3c8678ccd2963
b4e0 is the commit id
Objective: you want to fork Marcus's branch and make some changes and send pull request
Assume Marcus has a branch called "jacc" that you want to work on and fix.
3 steps:
- Remote add Marcus's repo.
- Fetch Marcus's repo.
- Checkout Marcus's branch into your own branch called "marcus"
$ git remote add mmoyses git://github.com/mmoyses/jboss-as.git $ git fetch mmoyses remote: Counting objects: 404, done. remote: Compressing objects: 100% (69/69), done. remote: Total 183 (delta 93), reused 158 (delta 71) Receiving objects: 100% (183/183), 36.44 KiB, done. Resolving deltas: 100% (93/93), completed with 53 local objects. From git://github.com/mmoyses/jboss-as * [new branch] ds -> mmoyses/ds * [new branch] infinispan_5_CR6 -> mmoyses/infinispan_5_CR6 * [new branch] jacc -> mmoyses/jacc * [new branch] master -> mmoyses/master $ git checkout -b marcus mmoyses/jacc Branch marcus set up to track remote branch jacc from mmoyses. Switched to a new branch 'marcus' $ git status # On branch marcus nothing to commit (working directory clean)
Objective: Discard changes to some local files (something like svn revert)
$ git status # On branch marcus # 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: ejb3/src/main/java/org/jboss/as/ejb3/subsystem/EJB3SubsystemAdd.java # modified: server/src/main/java/org/jboss/as/server/deployment/Phase.java # modified: testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/AnnotationAuthorizationTestCase.java # modified: testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/AuthenticationTestCase.java # modified: testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/SecurityDDOverrideTestCase.java # modified: testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/SecurityTest.java # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/JACCAuthorizationTestCase.java no changes added to commit (use "git add" and/or "git commit -a") $> git checkout testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/AnnotationAuthorizationTestCase.java testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/AuthenticationTestCase.java testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/SecurityDDOverrideTestCase.java testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/SecurityTest.java anil@localhost:~/as7/jboss-as$ git status # On branch marcus # 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: ejb3/src/main/java/org/jboss/as/ejb3/subsystem/EJB3SubsystemAdd.java # modified: server/src/main/java/org/jboss/as/server/deployment/Phase.java # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # testsuite/integration/src/test/java/org/jboss/as/test/integration/ejb/security/JACCAuthorizationTestCase.java no changes added to commit (use "git add" and/or "git commit -a")
Basically, I just used git checkout file(s) to throw away changes in those.
Objective: Get away from the "Not currently on any branch" message
A use case would be something like: you are on a topic branch. Then you rebase to upstream master. You get a conflict. You fix it. Commit it etc. When you do a git status, you see the "Not currently on any branch" message.
It is really not a cause for panic. What has happened is that the HEAD pointer is out of whack due to the conflicts during rebase.
You need to fix the conflict, check in the code, then do "$>git rebase --continue". Once all the conflicts are taken care of, you should see you are back on the branch in question.
An interaction is pasted here:
anil@localhost:~/as7/jboss-as$ git rebase --continue error: could not apply 02ae38e... using formatted logging hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' and run 'git rebase --continue' Could not apply 02ae38e... using formatted logging anil@localhost:~/as7/jboss-as$ git status # Not currently on any branch. # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: security/src/main/java/org/jboss/as/security/plugins/JNDIBasedSecurityManagement.java # modified: security/src/main/java/org/jboss/as/security/service/JaasConfigurationService.java # modified: security/src/main/java/org/jboss/as/security/service/JaccService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityBootstrapService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityDomainService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityManagementService.java # modified: security/src/main/java/org/jboss/as/security/service/SubjectFactoryService.java # modified: web/src/main/java/org/jboss/as/web/security/ExtendedFormAuthenticator.java # modified: web/src/main/java/org/jboss/as/web/security/JBossWebRealm.java # modified: web/src/main/java/org/jboss/as/web/security/SecurityContextAssociationValve.java # modified: web/src/main/java/org/jboss/as/web/security/WarJaccService.java # # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) # (use "git add/rm <file>..." as appropriate to mark resolution) # # deleted by us: security/src/main/java/org/jboss/as/security/SecuritySubsystemAdd.java # anil@localhost:~/as7/jboss-as$ git commit -a -m "merging" U security/src/main/java/org/jboss/as/security/SecuritySubsystemAdd.java fatal: 'commit' is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm <file>' as appropriate to mark resolution and make a commit, or use 'git commit -a'. anil@localhost:~/as7/jboss-as$ git rm security/src/main/java/org/jboss/as/security/SecuritySubsystemAdd.java security/src/main/java/org/jboss/as/security/SecuritySubsystemAdd.java: needs merge rm 'security/src/main/java/org/jboss/as/security/SecuritySubsystemAdd.java' anil@localhost:~/as7/jboss-as$ git status # Not currently on any branch. # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: security/src/main/java/org/jboss/as/security/plugins/JNDIBasedSecurityManagement.java # modified: security/src/main/java/org/jboss/as/security/service/JaasConfigurationService.java # modified: security/src/main/java/org/jboss/as/security/service/JaccService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityBootstrapService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityDomainService.java # modified: security/src/main/java/org/jboss/as/security/service/SecurityManagementService.java # modified: security/src/main/java/org/jboss/as/security/service/SubjectFactoryService.java # modified: web/src/main/java/org/jboss/as/web/security/ExtendedFormAuthenticator.java # modified: web/src/main/java/org/jboss/as/web/security/JBossWebRealm.java # modified: web/src/main/java/org/jboss/as/web/security/SecurityContextAssociationValve.java # modified: web/src/main/java/org/jboss/as/web/security/WarJaccService.java # anil@localhost:~/as7/jboss-as$ git commit -a -m "merging" [detached HEAD b38ff61] merging 11 files changed, 51 insertions(+), 87 deletions(-) anil@localhost:~/as7/jboss-as$ git status # Not currently on any branch. nothing to commit (working directory clean) anil@localhost:~/as7/jboss-as$ git rebase --continue error: could not apply 9ae9a18... ejb jacc hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' and run 'git rebase --continue' Could not apply 9ae9a18... ejb jacc anil@localhost:~/as7/jboss-as$ git status # Not currently on any branch. # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: build/src/main/resources/modules/org/jboss/as/ejb3/main/module.xml # modified: ejb3/src/main/java/org/jboss/as/ejb3/EJBMethodIdentifier.java # modified: ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponentDescription.java # new file: ejb3/src/main/java/org/jboss/as/ejb3/deployment/EjbSecurityDeployer.java # modified: ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/MethodPermissionsMergingProcessor.java # new file: ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/security/JaccEjbDeploymentProcessor.java # new file: ejb3/src/main/java/org/jboss/as/ejb3/security/EjbJaccService.java # # Unmerged paths: # (use "git reset HEAD <file>..." to unstage) # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: ejb3/src/main/java/org/jboss/as/ejb3/subsystem/EJB3SubsystemAdd.java # anil@localhost:~/as7/jboss-as$ git commit -a -m "merging" [detached HEAD 9a4812f] merging 8 files changed, 356 insertions(+), 7 deletions(-) create mode 100644 ejb3/src/main/java/org/jboss/as/ejb3/deployment/EjbSecurityDeployer.java create mode 100644 ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/security/JaccEjbDeploymentProcessor.java create mode 100644 ejb3/src/main/java/org/jboss/as/ejb3/security/EjbJaccService.java anil@localhost:~/as7/jboss-as$ git rebase --continue Successfully rebased and updated refs/heads/marcus. anil@localhost:~/as7/jboss-as$ git status # On branch marcus # Your branch and 'mmoyses/jacc' have diverged, # and have 232 and 5 different commit(s) each, respectively. # nothing to commit (working directory clean) anil@localhost:~/as7/jboss-as$ git push origin marcus Enter passphrase for key '/home/anil/.ssh/id_rsa': To git@github.com:anilsaldhana/jboss-as.git ! [rejected] marcus -> marcus (non-fast-forward) error: failed to push some refs to 'git@github.com:anilsaldhana/jboss-as.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. anil@localhost:~/as7/jboss-as$ git status # On branch marcus # Your branch and 'mmoyses/jacc' have diverged, # and have 232 and 5 different commit(s) each, respectively. # nothing to commit (working directory clean) anil@localhost:~/as7/jboss-as$ git push origin marcus -f Enter passphrase for key '/home/anil/.ssh/id_rsa': Counting objects: 230, done. Delta compression using up to 2 threads. Compressing objects: 100% (97/97), done. Writing objects: 100% (166/166), 31.13 KiB, done. Total 166 (delta 83), reused 37 (delta 30) To git@github.com:anilsaldhana/jboss-as.git + 3a93b78...54fa22b marcus -> marcus (forced update) anil@localhost:~/as7/jboss-as$ git status # On branch marcus # Your branch and 'mmoyses/jacc' have diverged, # and have 232 and 5 different commit(s) each, respectively. # # 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: ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/RunAsMergingProcessor.java # modified: ejb3/src/main/java/org/jboss/as/ejb3/subsystem/EJB3SubsystemAdd.java # no changes added to commit (use "git add" and/or "git commit -a") anil@localhost:~/as7/jboss-as$ git commit -a -m "fix errors" [marcus 2733c70] fix errors 2 files changed, 1 insertions(+), 4 deletions(-) anil@localhost:~/as7/jboss-as$ git push origin marcus Enter passphrase for key '/home/anil/.ssh/id_rsa': Counting objects: 31, done. Delta compression using up to 2 threads. Compressing objects: 100% (12/12), done. Writing objects: 100% (16/16), 1.07 KiB, done. Total 16 (delta 8), reused 0 (delta 0) To git@github.com:anilsaldhana/jboss-as.git 54fa22b..2733c70 marcus -> marcus anil@localhost:~/as7/jboss-as$
Objective: Get later updates from upstream while rebasing
$> git fetch upstream $> git rebase -i upstream/master Successfully rebased and updated refs/heads/master. $> git push -f
General Chat that you may find useful
Topic: Reset master, rebase etc
(03:34:03 PM) asaldhan: dmlloyd: if I reset my master, I do not have to do a push? (03:34:24 PM) dmlloyd: it depends on whether you want to also reset your remote to upstream/master (03:34:37 PM) asaldhan: dmlloyd: yeah I want to reset basically. (03:34:51 PM) dmlloyd: well if your remote was already reset to upstream then you don't need to (03:34:59 PM) dmlloyd: usually a "git status" will tell you if you've diverted (03:35:00 PM) asaldhan: dmlloyd: case when I have totally messed up my master. (03:35:03 PM) dmlloyd: diverged* (03:35:16 PM) dmlloyd: it's not like svn (03:35:22 PM) dmlloyd: your local copy isn't a slave of the remote copy (03:35:31 PM) dmlloyd: they're two isolated git repositories (03:35:53 PM) dmlloyd: so if you haven't pushed anything to your origin/master in a while then it won't have changed without your knowledge (03:35:57 PM) asaldhan: dmlloyd: right. but if I have checked in commits to my master and they are bogus. (03:36:13 PM) dmlloyd: when you commit, it commits into the repository local to your machine (03:36:22 PM) dmlloyd: your local checkout is a complete repository (03:36:24 PM) asaldhan: dmlloyd: I meant pushed (03:36:42 PM) asaldhan: dmlloyd: if I have pushed some changes to my master and they are screwed up in relation to upstream (03:36:45 PM) dmlloyd: if you want to change your remote origin/master then yes pushing is what you want to do (03:37:36 PM) asaldhan: dmlloyd: when I reset git reset --hard upstream/master (03:37:41 PM) asaldhan: dmlloyd: what happened? (03:37:49 PM) asaldhan: dmlloyd: local branch was replaced with upstream/master? (03:37:57 PM) dmlloyd: you're changing your local master to point to the same commit as upstream/master (03:38:19 PM) dmlloyd: where upstream/master is as of the last time you did "git fetch upstream" (03:38:19 PM) asaldhan: dmlloyd: now I want my master to get synched with upstream/master. (03:38:56 PM) dmlloyd: if you have local commits and you want to combine your local commits with upstream commits, use "git rebase upstream/master", which will put the new upstream commits chronologically before your local commits. (03:39:09 PM) dmlloyd: well, sequentially before. whatever. (03:39:33 PM) asaldhan: Interactive rebase already started (03:39:38 PM) asaldhan: dmlloyd: ^ whats that? (03:39:46 PM) dmlloyd: that means you're in the middle of a rebase already. (03:39:50 PM) dmlloyd: "git rebase --cancel" (03:39:59 PM) dmlloyd: or maybe "--abort" I forget (03:40:17 PM) dmlloyd: use "git log upstream/master..master" to see what you've got that upstream hasn't, and "git log master..upstream/master" to see what upstream's got that you haven't
CheatSheets/References
- http://cheat.errtheblog.com/s/git/
- http://www.silverwareconsulting.com/index.cfm/2010/6/6/Using-Git-Rebase-to-Squash-Commits (Using Git Rebase to Squash Commits)
Comments