title | layout | category |
---|---|---|
Git Tips & Tricks |
post |
coding |
{{TOC}}
Find the last commit that affected the given path. As the file isn't in the HEAD commit, this commit must have deleted it.
git rev-list -n 1 HEAD -- <file_path>
Then checkout the version at the commit before, using the caret (^
) symbol:
git checkout <deleting_commit>^ -- <file_path>
Or in one command, if $file
is the file in question.
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
This worked for me:
git clone file:////<host>/<share>/<path>
edit: For example, if your main machine has the IP 192.168.10.51
and the computer name main, and it has a share named code which itself is a git repository, the both of the following commands should work equally:
git clone file:////main/code
git clone file:////192.168.10.51/code
If the git repository is in a subdirectory, simply append the path.
To change a commit message of the most recent (unpushed) commit, you can simply use
git commit --amend -m 'new message'
To change messages of (unpushed) commits further in the past:
git rebase -i [COMMIT BEFORE THE FIRST YOU WANT TO EDIT]
Mark all messages to be changed with "edit". Git will start the rebasing and stop at every marked commit. For each of those, do a
git commit --amend -m 'new message'git rebase --continue
git push origin --delete <branchName>
git clean -fd
To search for commit content (i.e., actual lines of source, as opposed to commit messages and the like), what you need to do is:
git grep <regexp> $(git rev-list --all)
Updates: git rev-list --all | xargs git grep expression
will work if you run into an "Argument list too long" error
- Edit
.gitignore
to match the file you want to ignore git rm --cached /path/to/file
A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".