If one wants to see the commits that are in the 'dev' branch that are not in the 'master' branch, we can do dev
git log — <path name/file name>
git log –stat <path> so that we can see the impact of each commit on the file.
git log –pretty=oneline HEAD~3…HEAD~7 | sed -s ‘s/^[a-z0-9 ]\{41\}//g’
Undo a commit and redo
$ git commit …
$ git reset –soft HEAD^ (1)
$ edit (2)
$ git add …. (3)
$ git commit -c ORIG_HEAD (4)
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before “reset”.
Make corrections to working tree files.
Stage changes for commit.
“reset” copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead
Untrack a directory/file w/o actually deleting it
Th e following will cause git to untrack your directory and all files under it without actually deleting them:
git rm -r –cached <your directory>
List all commits for a specific file
git log — <path name/file name>
git log –stat <path> so that we can see the impact of each commit on the file.
^master
, or vice versa. Note that the Windows command-line treats ^
as a special character, in which case you'll need to surround ^master
in quotes.$ git log --oneline dev ^master fg23456 debug flag added 5890bha memory corruption bug fixed $ git log --oneline master ^dev 945f70c reusing variable
List all commits for a specific file
git log — <path name/file name>
git log –stat <path> so that we can see the impact of each commit on the file.
git log –pretty=oneline HEAD~3…HEAD~7 | sed -s ‘s/^[a-z0-9 ]\{41\}//g’
Undo a commit and redo
$ git commit …
$ git reset –soft HEAD^ (1)
$ edit (2)
$ git add …. (3)
$ git commit -c ORIG_HEAD (4)
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before “reset”.
Make corrections to working tree files.
Stage changes for commit.
“reset” copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead
Untrack a directory/file w/o actually deleting it
Th e following will cause git to untrack your directory and all files under it without actually deleting them:
git rm -r –cached <your directory>
List all commits for a specific file
git log — <path name/file name>
git log –stat <path> so that we can see the impact of each commit on the file.
Git tagging and using commit numbers as build #s
Use tags to mark commits with version numbers:
git tag -a v2.5 -m ‘Version 2.5′
Then use the describe command:
git describe –tags –long
This gives you a string of the format:
v2.5-0-deadbeef
^ ^ ^
| | |
| | SHA of HEAD
| |
| number of commits since last tag
|
last tag
Remove empty directories in git
Suppose you want to remove empty directories in git but wanna make sure what git will delete run
“git clean -fdn ” to confirm then run git clean -fd to delete the untracked directories.
Create dummy commits in git
Sometimes you may just want to create a dummy commit in the git without actually adding or modifying files.
git commit –allow-empty -m ‘Dummy commit to create the first tag in UI code ‘
Rename a tag in git
I wanted to apply the same tag name to two diffrent branches in the same repository but git doesn’t allow that.
so I prepended the tag names with a string like MYSQL,MSSQL,ORACLE and it worked
git tag “MSSQL_2.30.0″ “2.30.0″ -f -m “Prepending DB type to the existing tag name”
usage :
git tag <new_tag> <old_tag> -f -m <message>
-f is for forceful renaming
svn -v equivalent for git
SVN’s log has a “-v” mode that outputs filenames of files changed in
each commit, like so:Try one of the following, as git equivalent:git log –name-status
or
git log –name-only
or
git log –stat
each commit, like so:Try one of the following, as git equivalent:git log –name-status
or
git log –name-only
or
git log –stat
To check git messages between two commits/sha1s
git log –pretty=oneline HEAD~3…HEAD~7 | sed -s ‘s/^[a-z0-9 ]\{41\}//g’
we are stripping the sha1 with sed here.
Switch to a new branch
How to switch to a different branch in your repository when you actually cloned a branch (with -b option)
git checkout -b <new_branch_name> remotes/origin/<remote_branch>
eg:
git checkout -b graham_2.30_STABLE remotes/origin/graham_2.30_STABLE
How to check list of files with conflict in git. This is needed while merging.1) git diff –name-only –diff-filter=M
2) grep -rH ‘<<<<<<< HEAD’ * | grep -v .git | cut -f1 -d : | sort | uniq
2) grep -rH ‘<<<<<<< HEAD’ * | grep -v .git | cut -f1 -d : | sort | uniq
where
M: modification of the contents or mode of a file
Other possible values are :
A: addition of a file
C: copy of a file into a new one
D: deletion of a file
R: renaming of a file
T: change in the type of the file
U: file is unmerged (you must complete the merge before it can be committed)
X: “unknown” change type (most probably a bug, please report it)
A: addition of a file
C: copy of a file into a new one
D: deletion of a file
R: renaming of a file
T: change in the type of the file
U: file is unmerged (you must complete the merge before it can be committed)
X: “unknown” change type (most probably a bug, please report it)
Omit those commits
from master which are in staging(even the ones which have been
cherry-picked) or are patch-equivalent to a commit in staging
git log staging…master –cherry-pick –right-only –no-merges
git log staging…master –cherry-pick –right-only –no-merges
No comments:
Post a Comment