GIT Cheat list
- Individual Developer (Participant)
git-clone(1) from the upstream to prime your local repository.
git-pull(1) and git-fetch(1) from "origin" to keep up-to-date with the upstream.
git-push(1) to shared repository, if you adopt CVS style shared repository workflow.
git-format-patch(1) to prepare e-mail submission, if you adopt Linux kernel-style public
git grep maven2|grep "spec:B" Recursive search on GIT to find a specific string
- Individual Developer (Standalone)
git-init(1) to create a new repository.
git-show-branch(1) to see where you are.
git-log(1) to see what happened.
git-checkout(1) and git-branch(1) to switch branches.
git-add(1) to manage the index file.
git-diff(1) and git-status(1) to see what you are in the middle of doing.
git-commit(1) to advance the current branch.
git-reset(1) and git-checkout(1) (with pathname parameters) to undo changes.
git-merge(1) to merge between local branches.
git-rebase(1) to maintain topic branches.
git-tag(1) to mark known point.
- Real Life scenario:
803 git status
//Save current change in my local directory
804 git stash save
805 git status
//Create branch
806 git checkout -b groovyTemplate
//Revert previous stash save
807 git stash pop
//Add specific directory
808 git add redhat-packaging/rhecm-webapp/src/main/webapp/WEB-INF/conf/ecm-extension/artifacts/templates/file/
809 git status
//Add specific directory
810 git add redhat-packaging/rhecm-webapp/src/main/webapp/WEB-INF/conf/ecm-extension/ 811 git status
812 git commit
//Save changes to the branch
813 git status
//Replace my local workspace with orignal master
814 git checkout master
//Display branch info
815 git branch
816 git branch -v
//Get most recent code from remote repository
817 git pull
//Display log info
818 git log
823 git log groovyTemplate
Here the
992
shows the line number you want to see the revision information, +4
indicates how many lines you want to see after the specified line 992
. And lastly path-to-file
//Apply most current changes (step 812) to current workspace
824 git cherry-pick 8a31d6f2b4d78d9edc83647afe1df705f521ab79
- How to update branch with most current content from master.
git pull
git checkout groovyTemplate
git rebase master
//In case of conflicts:
git status
//Edit file and reconciliate content (look for red tag/brackets, etc...).
git rebase --continue
git log
- Git pull error:
Please, commit your changes or stash them before you can merge.
If you don't care about the changes, run:
git reset --hard
git pull
- Add color to status
name = john doe
email = jdoe@redhat.com
[diff]
color = auto
[pager]
color = true
[status]
color = auto
From: Ariejan.net
I bet the following has happened to you: you are happily working on a project and are in the middle of something. You are not ready to commit your changes, because you your tests don’t pass yet. Then your client calls with a bug report that needs to be fixed right now. (You know how clients can be.)
So, what do you do? Throw away your current changes to make the patch? Checkout a clean copy of your project to make the changes? No! You just stash your changes away, and make the patch! Afterward you grab your changes back and continue work.
Git features The Stash, which is as much as a good place to store uncommitted changes. When you stash you changes, the will be stored, and your working copy will be reverted to HEAD (the last commit revision) of your code.
When you restore your stash, you changes are reapplied and you continue working on your code.
Stash your current changes
$ git stash save
Saved "WIP on master: e71813e..."
List current stashes
Yes, you can have more than one!! The stash works like a stack. Every time you save a new stash, it’s put on top of the stack.
$ git stash list
stash@{0}: WIP on master: e71813e..."
Note the stash@{0} part? That’s your stash ID, you’ll need it to restore it later on. Let’s do that right now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.
Apply a stash
$ git stash apply stash@{0}
You may notice the stash is still there after you have applied it. You can drop it if you don’t need it any more.
$ git stash drop stash@{0}
Or, because the stash acts like a stack, you can pop off the last stash you saved:
$ git stash pop
If you want to wipe all your stashes away, run the ‘clear’ command:
$ git stash clear
It may very well be that you don’t use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.
$ git stash
...
$ git stash pop
Feel free to experiment with the stash before using it on some really important work.
- Revert to an old configuration:
git checkout -b newbranch processid
- Checkout new branch
1012 git checkout -b str17 -t origin/str17
Change Origin:
git remote -v
500 git remote -D origin
501 git remote remove origin
502 git remote add origin https://xxxx.xxx.xxx
Git history for a single file:
git log --pretty=format:"%h - %an, %ar : %s" ParticipantControllerTests.javaChange Origin:
git remote -v
500 git remote -D origin
501 git remote remove origin
502 git remote add origin https://xxxx.xxx.xxx
How to find stuff in Git
Add Remote repo to existing repo:
You can't merge a repository into a branch. You can merge a branch from another repository into a branch in your local repository. Assuming that you have two repositories, foo
and bar
both located in your current directory:
$ ls
foo bar
Change into the foo
repository:
$ cd foo
Add the bar
repository as a remote and fetch it:
$ git remote add bar ../bar
$ git remote update
Create a new branch baz
in the foo
repository based on whatever your current branch is:
$ git switch -c baz
Merge branch somebranch
from the bar
repository into the current branch:
$ git merge --allow-unrelated-histories bar/somebranch
(--allow-unrelated-histories
is not required prior to git version 2.9)
No comments:
Post a Comment