Open main menu

Changes

→‎Put your project on GitHub: add new short procedure
<code>git grep</code> only works on the current content of your working copy. To search through all revisions, you can use something like
<source lang="bash">
# -F is --fixed-strings
# Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched.
git rev-list --all | ( while read revision; do git grep -F 'wgAWSCredentials' $revision; done; )
</source>
Credit: there's a clear explanation at https://www.git-tower.com/learn/git/faq/undo-last-commit
 
==Good and Consistent commit messages==
You hopefully know what constitutes a [https://cbea.ms/git-commit/ good] [https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html commit message]. What about consistency? Say you need to add standard language to every commit message like
<tt>"This work was performed for NASA GRC-ATF by WikiWorks per NASA Contract NNC15BA02B."</tt>
 
To consistently format your commit messages, use the configuration parameter <code>commit.template</code> which you can do with <code>git config</code>, or else in your ~/.gitconfig file. Here's my [[Git/commit.template|commit.template]]
 
https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message
 
The GitLab project uses the concept of commit templates<ref>https://docs.gitlab.com/ee/user/project/merge_requests/commit_templates.html</ref>
 
==Git Branch==
<br />
== How did I get here? ==
What branch did this branch originate from? Or more precisely, what's the nearest ancestor commit on a separate branch?<syntaxhighlight lang="bash" line="1">
branch=`git rev-parse --abbrev-ref HEAD` \
</syntaxhighlight>Explanation:
# Grab the name of the current branch.# Show all commits (with errors or warnings going to dev null).# Ancestors of the current commit are indicated by a star. Filter out everything else.# Ignore all the commits in the current branch.# The first commit remaining is the nearest ancestor from another branch.# Branch names are displayed [in brackets]. Ignore the brackets and everything else.# Sometimes the branch name will include a ~2 or ^1 to indicate how many commits are between the referenced commit and the branch tip. We don't care. Ignore them. <ref>https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch</ref>
==Don't merge, Rebase!==
Been hacking away on a project and now it's time to unveil it? Here are the quick and easy steps to get your local repo into your GitHub account.
 
The short version is
 
# Go to GitHub.com and create a new repo - but only create a README and/or LICENSE (the less the better).
# Copy the HTTPS "clone" URL (or the SSH one if you have an authorized key on the remote host).
# Go to your remote host where you have developed your code
# git init your project if you haven't already. And also configure git with user.name and user.email
# git add .
# git commit -m 'First commit'
# git remote add the URL from step 2
# git pull --rebase
# git push
 
<br />
<source lang="bash">
# first make a "bare" clone
I know how to configure my user and email, but how do I tell git to remember my password for repos that I'm interacting with?
The answer is credential helper
 
<br />
 
==Rewriting History==
Developers need git as a way to track changes and collaborate on software. Release Engineers need git, and '''higher-level''' tools to manage entire repositories of code. Whether Developer or Release Engineer, sometimes you need a do over.
 
When [https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History rewriting history in your git project], If an interactive git rebase using 'edit' or 'reword' doesn't suffice for your use-case, you are probably looking for a higher-level tool.
 
To make subtle changes, or even large changes on a whole series of commits in a git repository, [https://github.com/newren/git-filter-repo/ <code>git filter-repo</code>](Python) is that tool. The git maintainers themselves do '''NOT''' recommend using <code>git filter-branch</code> - which is slow and painful and prone to problems. Consult the '''Git Filter Repo''' [https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html User Manual] for examples.
{{References}}