Always_a_learner
Always_a_learner

Reputation: 5055

How to re commit same changes in git branch

I am using git for a weeks now. I am working in a feature branch, sometimes when I push code into my branch it shows lot of conflicts with develop branch. so I this time I followed following steps to avoid unwanted conflicts and problems at work place :(

  1. git branch abc

  2. git checkout abc

  3. did my work
  4. git stash
  5. git pull origin develop
  6. got conflicts
  7. Resolved conflicts and also git stash pop
  8. git commit-m'message' // Don't know how merging removed lines which are not part of conflict
  9. git push origin

Now these step resulted in committing of 2 files, one in which I resolved conflicts and one in which I worked. Say File1 and File2 respectively.

Now I need to re push my code but only file2 i.e one in which I worked not in which I did conflict resolving and all.

But git status will show nothing as I have already done all the committing and pushing. Also during some of the auto-merging the necessary code is removed from File1. How to bring that back?

Any help would be appreciated?

As I am still learning GIT so any explanation would help me and others.

I am using BITBUCKET.

Thanks!!

Upvotes: 0

Views: 1831

Answers (2)

marilia15
marilia15

Reputation: 11

To extend previous answer, I would add: Git stash will save your changes in a "pocket" if they are not ready for a commit. But your changes are ready, so it is not necessary.

About your question in previous comment (I do not have enough reputation for answer you in a comment): git pull update your local repository and your working directory with the changes in the remote repository, is a shortcut for git fetch followed by git merge. But, as git merge have some drawbacks about the history, could be useful to used git fetch + git rebase instead.

Git rebase works locally, so it could be used in an homologous way to git merge, but not git pull!. Many answers will explain better than me about git rebase, I hope to help a little bit.

Upvotes: 1

Jamie Bisotti
Jamie Bisotti

Reputation: 2685

For #1 & #2: They can be combined -- git checkout -b abc

For #4: Why did you stash? I believe you should have committed your changes here.

For #6: Conflicts where? On your newly created feature branch? That shouldn't be possible.

A typical work-flow would be as follows:

  1. Make sure the main branch (master, or developer, or whatever) is up-to-date. I'll use master for this example.
    • git checkout master
    • git fetch
    • git rebase origin/master
  2. Create and checkout the feature branch
    • git checkout -b featureBranch
  3. Make changes
  4. Commit changes to featureBranch (ideally, this will be done multiple times; not a single large commit)
    • git add . # This is just one example; add selectively, as-is appropriate
    • git commit
  5. Push local featureBranch to the remote, for review or whatever
    • git push origin featureBranch
  6. When ready (e.g. reviewed and approved), merge featureBranch to master
    1. Rebase featureBranch against the latest master
      • git checkout featureBranch
      • git fetch
      • git rebase origin/master
    2. Make sure the master is up-to-date
      • git checkout master
      • git rebase origin/master
    3. Merge
      • git merge --no-fast-forward featureBranch

This workflow, via rebasing featureBranch before merging & using non-fast-forward merging, will result in a linear, yet delineated, history of master.

Good luck!

Upvotes: 1

Related Questions