Editing
Git Cookbook
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Reports and diffs == === View all branches and commit messages: === <syntaxhighlight lang="bash"> $ git log --oneline </syntaxhighlight> === View commit messages for a single branch: === <syntaxhighlight lang="bash"> $ git log --oneline [branchname] </syntaxhighlight> === View the files touched between two commits === Where you include just enough of SHA1 and SHA2 to identify the commits (usually about 4 characters). <syntaxhighlight lang="bash"> $ git diff --name-only SHA1 SHA2 </syntaxhighlight> === View all files modified by the commits in a single branch === <syntaxhighlight lang="bash"> $ git diff --name-status master..<branch> </syntaxhighlight> === List all the files in a single commit === One way (preferred): <syntaxhighlight lang="bash"> $ git diff-tree --no-commit-id --name-only -r bd61ad98 index.html javascript/application.js javascript/ie6.js </syntaxhighlight> Another way: <syntaxhighlight lang="bash"> $ git show --pretty="format:" --name-only bd61ad98 index.html javascript/application.js javascript/ie6.js </syntaxhighlight> The `--no-commit-id` suppresses the commit ID output. The `--pretty` argument specifies an empty format string to avoid the cruft at the beginning. The `--name-only` argument shows only the file names that were affected (Thanks Hank). The `-r` argument is to recurse into sub-trees === View all commits for a single file === <syntaxhighlight lang="bash"> $ git log --oneline <path> </syntaxhighlight> === View changes in a single file between two branches === <syntaxhighlight lang="bash"> $ git diff <branch1>...<branch2> -- <path/to/file> </syntaxhighlight> === Create a patch file for work done in a git branch === To get all the changes after a specific commit: <syntaxhighlight lang="bash"> $ git diff -p <commit_string> > <path/to/patchfile.patch> </syntaxhighlight> Or between two specific commits (the newer one goes first): <syntaxhighlight lang="bash"> $ git diff -p <newer_commit_string> <older_commit_string> > <path/to/patchfile.patch> </syntaxhighlight> (To narrow it down to a specific file, see the 'git diff` example above.) <syntaxhighlight lang="bash"> $ git diff -p <branch1>...<branch2> > <path/to/patchfile.patch> </syntaxhighlight> === Applying a patch created with "git diff" === <syntaxhighlight lang="bash"> $ patch -p1 < <path/to/patchfile.patch> </syntaxhighlight> If the directory structure is different, say if you are editing `myapp2/path/to/file_to_edit.py` using changes made to `myapp1/path/to/file_to_edit.py` then enter the new path when prompted by the `patch` program.
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information