Initialize a repository by,
git init
Add files to the repo by,
git add .
git add file
removal,
git rm file
rename,
git mv old new
This will add all the file under the directory recursively.
Now do a base commit,
git commit -a
This will commit all the files to the repository .
To create a new branch for editing,
git checkout -b devel
Commit only required changes
If you have many changes, for example in folders like drivers/video and drivers/sound. And you only want to commit the changes to drivers/video, then git add those files and type git commit without using -a option.
git add drivers/video/
git commit
If your master has grown beyond the point when you took the devel branch, you can update the master and you can rebase the devel branch to master,
git rebase -i master
Have a look here for more doubts about merging issues.
http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge
configuring the .gitconfig file,
My .gitconfig file looks like this
cat ~/.gitconfig
[user]
name = "Arun Sudhilal"
email = "arun.sudhilal@lntinfotech.com"
[core]
editor = vim
[color]
ui = auto
[merge]
tool = vimdiff
Creating patches,
git format-patch HEAD~1
HEAD^^ == HEAD~2
---
git show
git show --stat
git show --name-status HEAD~3
git show HEAD:file
contents.....
git log
git log HEAD~10..
git log --author=arun
git log --committer=arun
git log --grep="commit.*message.*text"
For expample if i want to grep "frame", then
git log --grep="grame"
git log -S "some code change"
git log file
git grep -e "pattern" -- some/file
git branch name commit
git checkout name
git checkout -b name commit
git checkout -m name
merge outstanding diff onto branch "name", can result in conflict.
git tag -a -m "got somewhere" good
git rebase
moves new work to a new base line
git fetch
Just update the remote, but doesn't update work space
git fetch + git merge = git pull
to apply a patch in you local tree,
git am -3
Pushing to the repositories,
* git push origin will push changes from all local branches to matching branches the origin remote
* git push origin master will push changes from the local master branch to the remote master branch
* git push origin master:staginwill push changes from the local master branch to the remote staging branch if it exists
Recovering lost commits,Sometime by mistake you might have done git reset --hard HEAD^. Then you realise that you need that commit. Dont worry, git has a way to recover your lost commit.
git reflog
Git tracks almost everything you does. If you feels that you have screwed up you repo by rebase, merge or even by reset, you can dig reflog and get it back.
git reflog output may be something like this,
6d2a85e HEAD@{0}: merge 6d2a85e: Fast-forward
28eb495 HEAD@{1}: 28eb49561313ce479f228acea6d25a2bf20166a8: updating HEAD
6d2a85e HEAD@{2}: pull : Fast-forward
6744afe HEAD@{3}: 6744afe5afa033763cdb4e698eea1a5febabae8e: updating HEAD
once you get this you can check with git show which commit you want. For here you can cherry-pic, merge or checkout.
.gitconfig
And this is how my .gitconfig looks like,
Renaming current branch,
git branch -m linux-linaro-tracking
Checkout with the same name as remote,
git co -t remotes/origin/linux-linaro
Suwon, S Korea
git init
Add files to the repo by,
git add .
git add file
removal,
git rm file
rename,
git mv old new
This will add all the file under the directory recursively.
Now do a base commit,
git commit -a
This will commit all the files to the repository .
To create a new branch for editing,
git checkout -b devel
Commit only required changes
If you have many changes, for example in folders like drivers/video and drivers/sound. And you only want to commit the changes to drivers/video, then git add those files and type git commit without using -a option.
git add drivers/video/
git commit
If your master has grown beyond the point when you took the devel branch, you can update the master and you can rebase the devel branch to master,
git rebase -i master
Have a look here for more doubts about merging issues.
http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge
My .gitconfig file looks like this
cat ~/.gitconfig
[user]
name = "Arun Sudhilal"
email = "arun.sudhilal@lntinfotech.com"
[core]
editor = vim
[color]
ui = auto
[merge]
tool = vimdiff
Creating patches,
git format-patch HEAD~1
HEAD^^ == HEAD~2
---
git show
git show --stat
git show --name-status HEAD~3
git show HEAD:file
contents.....
git log
git log HEAD~10..
git log --author=arun
git log --committer=arun
git log --grep="commit.*message.*text"
For expample if i want to grep "frame", then
git log --grep="grame"
git log -S "some code change"
git log file
git grep -e "pattern" -- some/file
git branch name commit
git checkout name
git checkout -b name commit
git checkout -m name
merge outstanding diff onto branch "name", can result in conflict.
git tag -a -m "got somewhere" good
git rebase
moves new work to a new base line
git fetch
Just update the remote, but doesn't update work space
git fetch + git merge = git pull
to apply a patch in you local tree,
git am -3
Pushing to the repositories,
* git push origin will push changes from all local branches to matching branches the origin remote
* git push origin master will push changes from the local master branch to the remote master branch
* git push origin master:staginwill push changes from the local master branch to the remote staging branch if it exists
Recovering lost commits,Sometime by mistake you might have done git reset --hard HEAD^. Then you realise that you need that commit. Dont worry, git has a way to recover your lost commit.
git reflog
Git tracks almost everything you does. If you feels that you have screwed up you repo by rebase, merge or even by reset, you can dig reflog and get it back.
git reflog output may be something like this,
6d2a85e HEAD@{0}: merge 6d2a85e: Fast-forward
28eb495 HEAD@{1}: 28eb49561313ce479f228acea6d25a2bf20166a8: updating HEAD
6d2a85e HEAD@{2}: pull : Fast-forward
6744afe HEAD@{3}: 6744afe5afa033763cdb4e698eea1a5febabae8e: updating HEAD
once you get this you can check with git show which commit you want. For here you can cherry-pic, merge or checkout.
Suwon, S Korea