It seems like a simple question, but why does this file have a question mark in front of it after I have run the commands "Hg push" and "Hg commit". How do I get this new file to upload to the mercurial server? Why did my mercurial commit leave behind a file?
#Xinl ➜ projectfolder hg status
? data/openend_coding/soundex_unaidedlogopay1.py
Quote from hg help status (hg's help is quite extensive and always worth a look!):
The codes used to show the status of files are:
M = modified
A = added
R = removed
C = clean
! = missing (deleted by non-hg command, but still tracked)
? = not tracked
I = ignored
= origin of the previous file (with --copies)
Before mercurial tracks a file you have to tell it to actually do so by means of hg add. Untracked files are never committed.
Related
I have spent a long time reading and trying to figure out git commit --amend, but I still do not understand how the # are used in the editmsg.
I am worried to edit this without knowing what I am doing because I have read that git commit --amend only does the most recent commit,and once I save and exit , it will be counted as a new commit.
I have accidentally committed and pushed (but the push failed) some large files. But I have also written scripts that were supposed to be pushed from the same commit as the large files.
I am trying to delete the lines with the large files in the new commit , but I don't understand how to do this.
This is my commit file below, but I don't understadn if I should delete the lines with the # (I tried this but it didn't work , and the git log is the same ):
the commit message of the one I want to change is here but I don't want to just change the message, I want to delete the large files in the commit so that the push works.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Thu Feb 8 18:30:32 2018 -0900
#
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# new file: script.py
# new file: super_large_file.npy <--- I deleted this line but it appeared again, it is becuase deleting a line with # is ignored? Do I just rewrite the stuff after the # lines?
My question is , why does deleting the line of the large file (including the # ) not work and the commit remains still wanting to push the large file?
Should I just rewrite the commit file without the # ? But I also read that git takes away the # , so I am confused
First, those are comments: removing a line starting with # has no effect in your git repository content.
They include hints and the list of files included with the commit.
I would recommend, in order to actually remove that file from your repo history, to use the new git filter-repo which replaces BFG and git filter-branch.
Note: if you get the following error message when running the above-mentioned commands:
Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`
it means you have to update git.
First: do that one copy of your local repo (a new clone)
See "Path based filtering":
git filter-repo --path file-to-remove --invert-paths
At the end, you can (if you are the only one working on that repository) do a git push --force
Second, the hints displayed in a commit messages are changing with with Git 2.25.1 (Feb. 2020): "git commit" gives output similar to "git status" when there is nothing to commit, but without honoring the advise.statusHints configuration variable, which has been corrected.
See discussion.
See commit 5c4f55f (17 Dec 2019) by Heba Waly (HebaWaly).
(Merged by Junio C Hamano -- gitster -- in commit 9403e5d, 22 Jan 2020)
commit: honor advice.statusHints when rejecting an empty commit
Signed-off-by: Heba Waly
In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, because giving the hints in the "git status" like output in the commit message template are too late to be useful (they say things like "'git add' to stage", but that is only possible after aborting the current "git commit" session).
But there is one case that the hints can be useful: When the current attempt to commit is rejected because no change is recorded in the index.
The message is given and "git commit" errors out, so the hints can immediately be followed by the user.
Teach the codepath to honor the configuration variable.
The hint (now visible in the commit message editor) will be:
no changes added to commit (use "git add" and/or "git commit -a")
I tried a different way than amending the commit , and removed the file completely from my local and github repositories. I am not sure how to keep it in my local repository still, but I don't know if this is necessary because I don't really understand the difference between my local repository and the local drive .
https://help.github.com/articles/removing-files-from-a-repository-s-history/
(I found this link from Bluemoon93's answer on Can't push to GitHub because of large file which I already deleted )
Context:
I'm learning how to use git with Eclipse and am using it for a small project with only a local repository.
Problem:
I just noticed that a commit I made earlier has an incorrect description attached to it.
There's nothing wrong with the files I committed or anything but for clarity's sake (if I want to revert or whatever) I'd like to change the description which is misleading.
I can't just amend previous commit as I have made more commits since then.
Floundering attempts to solve problem:
I variously tried creating new branches, amending commits and then rebasing, but end up with a bunch of scary looking merge conflicts and a spaghetti looking history tree.
I could just copy and paste my newer commits into txt files, revert back to the commit with the wrong info and start again from there, but I figure the whole point of using git is to avoid doing stuff like that.
Question:
Is there a simple way to just change an older commit's description text?
If not what are the steps for the complicated way in egit?!
If you already pushed the revisions somewhere: don't!
Otherwise: use git rebase -i <SOME_OLD_REVISION> and mark the commits to be changed with the r(eword) option.
Once you close the file that was popped up, rebasing will start and you'll be prompted for every commit you chose to enter the new commit message.
Assume you have the following commit history (newest first):
f6f6f6f last commit
d4d4d4d ...
c3c3c3c third commit
b2b2b2b second commit
a1a1a1a first commit
And want to change the messages for b2b2b2b and c3c3c3c, you would do
git rebase -i a1a1a1a
Next, your favourite editor will pop up and show you this dialog:
pick f6f6f6f last commit
pick ...
pick c3c3c3c third commit
pick b2b2b2b second commit
# Rebase b2b2b2b..f6f6f6f onto a1a1a1a
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Change pick to r or reword for commits b2b2b2b and c3c3c3c, save the file and exit the editor.
Next, rebasing will start.
For the commits you chose to reword, you could then enter the new commit message.
I am working on a project and I have to find the number of files added, deleted and modified since the last commit in mercurial hg.
hg status gives us the list of files which are modified, deleted and unknown. So using hg status is there any way i can get a count of all files added, deleted and modified?
Each file added, modified or deleted is listed on a line by itself, so you can count the lines for each. For instance, on Unix-like systems with the wc command:
hg status --modified | wc -l
Since the last commit it's always 0.
Describe your business-task in business-words
It is a very simple and stupid question,
I am working on 2 tasks and modified 2 sets of files in the code.
Now when I type 'hg ci', it checks in all the files. Can I remove certain files from the checkin i.e. do checking for only one task?
If I remove the files in the 'check in message' will they be removed from the checkin
Thanks for all the answers
This seems like a big flaw, My use case is very simple and general. Most of the time dev are working on various tasks , some are ready , some are not, bug fixes etc.
Now the only simple solution seems to be multiple local repos or clones
Use hg ci <files>... to commit only certain files in your working directory.
If you want to pick file by file you can use the record command. It ships with mercurial, but you have to turn it on if you want to use it by putting: record= in the [extensions] section of your ~/.hgrc.
It goes hunk by hunk, but you can answer for a whole file:
y - record this change
n - skip this change
s - skip remaining changes to this file
f - record remaining changes to this file
d - done, skip remaining changes and files
a - record all changes to all remaining files
q - quit, recording no changes
? - display help
I'll point out that if you're committing some files but not others it's certain that you've not run your test suite on the one change without the other, but maybe that doesn't apply in your case.
This isn't possible with mercurial out of the box. As have been suggested there are several ways of selecting what files you want to commit. To get this function via the commit message template, you would need an extension or a shell script wrapping the commit command. Here's one way to do that:
[alias]
ci = ! hg-partial-commit
hg-partial-commit:
#!/bin/sh
# partial commit
edit=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
filelist=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
logmessage=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
cleanup="rm -f '$edit' '$filelist' '$logmessage'"
trap "$cleanup" 0 1 2 3 15
(
echo user: $(hg debugconfig ui.username)
echo branch: $(hg branch)
hg parents --template 'parent: {rev}:{node|short} {author} {date|isodate}\n'
echo
echo 'Enter commit message. Select files to commit by deleting lines:'
hg status 'set:not unknown()' | sed -e 's/^/#/'
) | sed -e 's/^/HG: /' >"$edit"
${VISUAL:-${EDITOR:-vi}} "$edit"
egrep -v '^HG:' "$edit" >"$logmessage"
egrep '^HG: #' "$edit" | cut -c8- >"$filelist"
hg commit -l "$logmessage" "listfile:$filelist"
$cleanup
The real problem here is the fact that you're doing changes related to different tasks jumbled together. Mercurial has a few ways you can keep things separate.
Task Branches
Suppose you've been working on a task and you've checked in a few times since you last pulled, but things aren't ready to share yet.
o----o----B----o----o----o
Here, B is the revision where you started your changes. What we do is (after making sure our current changes are checked in):
> hg update -r B
<do our work on the other task>
> hg commit
We've now created a new branch with the changes for this task separated from the changes for our original task.
o----o----B----o----o----o
\
----o
We can do this for as many different tasks as we want. The only problem is that sometimes remembering which branch is which can be awkward. This is where features like bookmarks come in useful. A bookmark is a tag which moves forward as commits are made so that it always points at the head of a branch.
Mercurial Queues
MQ adds the ability to work on changes incrementally and move between them by pushing and poping then off a stack (or "Queue" I guess). So if I had a set of uncommitted changes that I needed to split up I'd:
> hg qrecord taska
> hg qrecord taskb
> hg qrecord taskc
I'd use the record extension (or more likely the crecord extension) to select which parts of files I want to select.
If I needed to go back to taska and make some changes:
> hg qpop; hg qpop # pop two off the queue to go back to task a
<Do changes>
> hg qrefresh # update task a with the new changes
When I want to turn the queue into normal changesets:
> hg qpush or hg qpop # get the changes I want converted onto the queue
> hg qfinish -a # converts mq changes to normal changesets
There's other methods too, but that will do for now.
You will unavoidably have to either specify the files that you want to add or the files you want to leave out. If you have a lot of files, as you indicate above, the following steps will simplify the procedure (I'm assuming a UNIX-ish system here, Windows would be slightly different).
First, generate a list of changed files:
hg status -mard -n >/tmp/changedlist.txt
The -mard options will list all files that were modified, added, removed, or delated. The -n option will list them without the status prefix so that all you have is a raw list of files.
Second, edit /tmp/changedlist.txt with your favorite text editor so that it contains only the files you wish to commit.
Third, commit these files:
hg commit `cat /tmp/changedlist.txt`
You will be able to review the files to be committed before actually performing the commit.
Alternatively, you can add more files to a commit incrementally by using
`hg commit --amend file...`
Here, hg commit --amend will not create a new commit, but add the new files to the existing commit. So, you start out with committing just a couple of files, then incrementally adding more until you are done. This still requires you to type all of them in.
For yet another alternative, you can use Mercurial Queues to split a commit in more sophisticated ways, but that's a bit more of an advanced topic.
Is there any way to take complete manual control over the merge process in Mercurial?
I want to be able to choose direction of file-merge, even for files without conflicts.
Is that possible?
Turn "pre-merge" off in your merge configuration. Then everything counts as a conflict and you can pick "left" or "right" for each and every file change.
[merge-tools]
mymergetool.premerge = False
from MergeToolConfiguration on the Mercurial wiki.
Edit your configuration file this way:
[ui]
merge = kdiff3
[merge-tools]
kdiff3.premerge = false
kdiff3.args=--L1 base --L2 local --L3 other $base $local $other -o $output
By default it puts the --auto argument on kdiff3 so kdiff3 auto merges.
A merge is always performed between the working directory's parent revision and another revision, by default the other head in your repository.
If you want to merge in the other "direction" you can change which branch is in your working directory by checking out a specific revision:
hg update -r [rev]
To see which heads you have in your repository run the following command:
hg heads
Alternatively, if you're using fetch you can use the --switch-parent option to merge in the other direction:
hg fetch --switch-parent
You can't change the direction of the merge on a file-by-file basis as Mercurial works with changesets which affect a whole repository not by tracking changes on to individual files like CVS.
In case of KDiff3 it is vital to add option --qall (see http://kdiff3.sourceforge.net/doc/documentation.html). There will be an automatic merge of some conflicts without this key (like "Automatically Solve Simple Conflicts" from "Merge" menu). Thus the more proper command line is:
[ui]
merge = kdiff3
[merge-tools]
kdiff3.premerge = False
kdiff3.args=$base $local $other -o $output --L1 base --L2 local --L3 other --qall